Reputation: 71
Im using Combobox filled with Tables Names. When I made Insert command and determine the table name by getting the values of the Combobox it didn't work
private void Form2_Load(object sender, EventArgs e)
{
Conn.Open();
foreach (DataRow dr in dt.Rows)
{
comboBox1.Items.Add(dr["TABLE_NAME"].ToString());
}
Conn.Close();
}
//cmd = new SqlCommand("insert into dbo."+ comboBox1.SelectedItems.ToString() +"(Phone, Email, Address) values('" + txt1.Text + "','" + txt2.Text + "','" + txt3.Text + "')", Conn);
Upvotes: 1
Views: 223
Reputation: 129
You can find there a very good resource for everything for combobox. You can use the datasource property and let know the values and display for what you need.
comboBox1.datasource = datatable;
comboBox1.displayname = "ColumnNameForDisplayName";
comboBox1.valuename = "ColumnsNameForValueName";
Upvotes: 1