3
Answers

inserting 10-12 items from listbox into sql database

anurag guhe

anurag guhe

8y
247
1
hi guys...I am developing windws form & in that form 1 is combox , 1 listbox & 1 button .... listbox containg items after selecting items from combobox now i want when i clicking on save button how should i am inserting the all items from listbox into sql database...here following is my code
 
private void Btn_Save_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConnectionString);
con.Open();
str = "insert into Customer_Entery_Form values('"+Lst_Bx_Service_Name.Items.ToString()+ "')";
com = new SqlCommand(str, con);
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("Records successfully Inserted");
Lst_Bx_Staff_Name.Items.Clear();
}
 
now the problem is that data is inserting successfully from listbox but when i am showing in sql database it shows like "System.Windows.Forms.ListBox+ObjectCollection
 
Answers (3)