Pat Tum

Pat Tum

  • NA
  • 16
  • 0

Another List Box Issue

Oct 31 2006 11:05 AM
I am a relative newcomer to C#, having started writing programs only 10 months ago. With the help of Mahesh Chands's ADO.Net in C# (and a few others), I have been able to decipher most of the code necessary to write basic programs, however, I have now reached an issue that I cannot find addressed specificaly in that (or any other) book. When I try to pass a List Box selection as a parameter to my database (MSSQL) using the following code snippet, it works perfectly as long as the list information is held as part of the collection. However, if it is from a List Box that has been populated by the database, I get the following error: Error: String or Binary Data would be truncated. The statement has been terminated. When using the Debugger, I see the program is trying to pass the following data instead of the "Selected Item": (System.Data.DataRowView) I have tried to add a Value Member reference to the code, but that makes the problem worse. I have never written in any forum before. Any assistance you can lend would be greatly appreciated. Here is the code for the list box and the parameter: //Sales Writer string Sql6 = "SELECT [Tech_ID]FROM [User]"; //Make the Command SqlCommand Comm6 = new SqlCommand(Sql6, Conn); //Pass the Command and Connection Comm6.CommandType = CommandType.Text; //Define the Command Type try { SqlDataAdapter da6 = new SqlDataAdapter(Comm6); //Create a Data Adapter DataSet ds6 = new DataSet(); //Create a Dataset da6.Fill(ds6, "User"); //Fill the Dataset DataTable dt6 = ds6.Tables["User"]; this.comboBoxWoSales.DataSource = dt6; this.comboBoxWoSales.DisplayMember = "Tech_Id"; } //Parameter Comm.Parameters.AddWithValue("@Mechanic", this.comboBoxWoMechanic.SelectedItem.ToString()); Thank you in advance for your help...Pat

Answers (2)