Hi,
I am really new to C# and access. I have a access database. I have connected it through dataadapter and databinding.
I get the data from the database to the combo. When ever I select an item I get the value for the corresponding item from the database and shown in a text box.
Now I would like to delete a record that is selected in the combo box. I have a delete button.
Here is the below which I tried:
I hve initalized the database connection and database already.
private void recorddeleteButton_Click(object sender, EventArgs e){
string
delStr = "Delete FROM [Test] Where fn = '" + combobox1.Text + "'";dAdapter = new OleDbDataAdapter(delStr, myConn);
dset = new DataSet();
dAdapter.TableMappings.Add("Table", "Test");
dAdapter.Fill(dset);
this.dviewmanager = dset.DefaultViewManager;
this.combobox1.DataSource = this.dviewmanager;
this.combobox1.DataBindings.clear();
this.combobox1.DisplayMember = "Test.fn";
}
but this doesn't do anything. I would like delete the selected Item and then update the combox box with the remaining records.
How do I go about doing it?
Awaiting your response!
Thanks!
Niradhip ChakrabortyPosted May 22, 2008, 12:07 PM
private void recorddeleteButton_Click(object sender, EventArgs e)
{
string strSQL;
SqlConnection con1 = null;
con1 = new SqlConnection(ConfigurationManager.AppSettings["con"].ToString());
con1.Open();
strSQL = "Delete from Users where usr_vch_name='" + combobox1.Text + "'";
SqlCommand sqlComm = new SqlCommand(strSQL, con1);
sqlComm.ExecuteNonQuery();
con1.Close();
}
Now this code will delete the record from combo box after that you clear the combo box and fill
again the combobox by the same way you initially filling in page load.
Try it if You cant do it send me the entire code I will modify that.