Ankita Ankita

Ankita Ankita

  • NA
  • 11
  • 28k

Storing wrong value "System.data.datarowview" in table.

Feb 6 2012 7:18 AM
public void InsertSusCode()
        {
         
            for( i=0;i<lstcsuspectcode.SelectedItems.Count; i++)
            {
              
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }
                     
                    string[] s = new string[lstcsuspectcode.SelectedItems.Count];
                    s[i]= lstcsuspectcode.SelectedItems[i].ToString();
                    string str="insert into casesuspect1(suspect_code) values('"+s[i]+"')";
                    SqlCommand cmd = new SqlCommand(str, con);
                    int r = cmd.ExecuteNonQuery();
                    if (r > 0)
                    {
                        MessageBox.Show("Suspect INSERTED SUCCESSFULLY.");
                    }
            }
        }


The above code stores value System.Data.DataRowView in the table casesuspect1? It should store the multiple selected items in list box. The suspectcode list box displays suspects name. So is there any mistake in the code? Any other suggesstion is also welcomed.



Answers (1)