I am making desktop application using C#.I have created a form in which there are various labels with respective textboxes,combox(like threshold id,name,date etc) and one listbox.I have taken 2 buttons add ,update for a form.I have taken group box in which there is a list box with 2 buttons add.delete.For a whole form it add/update the contents(like id,name,date and items of listbox(for each entry items in listbox vary).Now group box containing listbox,add/update button operate accordingly for each entry made for threshold id,name,date etc.the problem is when i add whole contents of the form .I get an
error
"Unable to cast object to type 'System.Data.DataRowView' to type 'System.String'.
I have checked when i dont include listbox coding ,there is no error and when i include listbox coding i get an error
below is the coding
private void btmadd_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=SW-PC-20;Integrated security =SSPI;Initial catalog=PSM");
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO" +
" Publicity_Threshold(Threshold_id,Threshold_Name,Media_method_ID,Media_Used,Starting_Date,Ending_Date,Duration_Tenure,State,City,Area,Target_Audience,Target_Audience_Volume,Walkins_Volume,Person_Incharge,Budget,Quantum_of_Threshold,Resources)" +
" VALUES" +
" (@Threshold_id,@Threshold_Name,@Media_method_ID,@Media_Used,@Starting_Date,@Ending_Date,@Duration_Tenure,@State,@City,@Area,@Target_Audience,@Target_Audience_Volume,@Walkins_Volume,@Person_Incharge,@Budget,@Quantum_of_Threshold,@Resources)", con);
cmd.Parameters.Add(new SqlParameter("@Threshold_id", Convert.ToInt32(txtThresholdID.Text)));
cmd.Parameters.Add(new SqlParameter("@Threshold_Name", cboThreholdname.Text));
cmd.Parameters.Add(new SqlParameter("@Media_method_ID", Convert.ToInt32(cbomethodid.Text)));
cmd.Parameters.Add(new SqlParameter("@Media_Used", cbomediaused.Text));
cmd.Parameters.Add(new SqlParameter("@Starting_Date", this.startingdate.Value));
cmd.Parameters.Add(new SqlParameter("@Ending_Date", this.endingdate.Value));
cmd.Parameters.Add(new SqlParameter("@Duration_Tenure", txtduration.Text));
cmd.Parameters.Add(new SqlParameter("@State", cboState.Text));
cmd.Parameters.Add(new SqlParameter("@City", cboCity.Text));
cmd.Parameters.Add(new SqlParameter("@Area", cboArea.Text));
cmd.Parameters.Add(new SqlParameter("@Target_Audience", cboTargetAudience.Text));
cmd.Parameters.Add(new SqlParameter("@Target_Audience_Volume", Convert.ToInt32(txtaudiencevolume.Text)));
cmd.Parameters.Add(new SqlParameter("@Walkins_Volume", Convert.ToInt32(txtinquiryvolume.Text)));
cmd.Parameters.Add(new SqlParameter("@Person_Incharge", txtperson.Text));
cmd.Parameters.Add(new SqlParameter("@Budget", Convert.ToInt32(txtBudget.Text)));
cmd.Parameters.Add(new SqlParameter("@Quantum_of_Threshold", Convert.ToInt32(txtQuantum.Text)));
string strC = "";
foreach (string itm in listBox1.Items)
{
strC = strC + " ," + itm;
}
cmd.Parameters.Add(new SqlParameter("@Resources",strC));
cmd.ExecuteNonQuery();
MessageBox.Show("Insertion successfully done");
}