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 "

Vinay SinghRank #604 · 4K reputationPosted Jul 13, 2016, 3:20 AM EDT
{
if (Lst_Bx_Service_Name.Items[i].Selected)
{
string selectedItem = Lst_Bx_Service_Name.Items[i].Text;
str =str + "insert into Customer_Entery_Form values('"+selectedItem + "');";
}
}
anurag guhe43 reputationPosted Jul 13, 2016, 3:35 AM EDT
anurag guhe43 reputationPosted Jul 13, 2016, 4:13 AM EDT