empty string
-
Hi I got following function. When I debug the code '"+Name+"' is Name="System.Data.DataRowView". Does anybody knows why? private void menuItem1_Select(object sender, System.EventArgs e) { string Name = this.listBox1.SelectedItem.ToString(); OleDbConnection conn = new OleDbConnection(connString); OleDbCommand dbCommand = new OleDbCommand("SELECT Beschreibung FROM tbl_T5 WHERE (Rechner = '"+Name+"')", conn); conn.Open(); OleDbDataReader dbReader; dbReader = dbCommand.ExecuteReader(); dbReader.Read(); if (dbReader.HasRows) { this.menuItem2.Text = dbReader["Beschreibung"].ToString(); } dbReader.Close(); conn.Close(); }
-
Hi I got following function. When I debug the code '"+Name+"' is Name="System.Data.DataRowView". Does anybody knows why? private void menuItem1_Select(object sender, System.EventArgs e) { string Name = this.listBox1.SelectedItem.ToString(); OleDbConnection conn = new OleDbConnection(connString); OleDbCommand dbCommand = new OleDbCommand("SELECT Beschreibung FROM tbl_T5 WHERE (Rechner = '"+Name+"')", conn); conn.Open(); OleDbDataReader dbReader; dbReader = dbCommand.ExecuteReader(); dbReader.Read(); if (dbReader.HasRows) { this.menuItem2.Text = dbReader["Beschreibung"].ToString(); } dbReader.Close(); conn.Close(); }
That's quite easy:
Name
is set at exactly one location, so the value you see is the result ofthis.listBox1.SelectedItem.ToString();
. That means the selected item in yourlistBox1
is aDataRowView
.DataRowView
doesn't have an overloadedToString
method, so you simply get the type name. But what's the question? Obviously you expectName
to be something else. Could it be that you don't want one of listBox1's items? Without further info we can only guess... mav -
That's quite easy:
Name
is set at exactly one location, so the value you see is the result ofthis.listBox1.SelectedItem.ToString();
. That means the selected item in yourlistBox1
is aDataRowView
.DataRowView
doesn't have an overloadedToString
method, so you simply get the type name. But what's the question? Obviously you expectName
to be something else. Could it be that you don't want one of listBox1's items? Without further info we can only guess... mav -
got it.. DataRowView dv =(DataRowView)this.listBox1.SelectedItem; this.menuItem2.Text = dv["Beschreibung"].ToString(); Thank you