c# deleting whole row in access database

Posted by user2978474 on Stack Overflow See other posts from Stack Overflow or by user2978474
Published on 2013-11-11T09:28:12Z Indexed on 2013/11/11 9:54 UTC
Read the original article Hit count: 243

Filed under:

I have question about my problem. Thru manustrip in form1 i have made new form2 when i click on a right option. This form is for deleting data in access database if you pick in combobox ID of row it deletes the whole row wher is ID 4 or somethig else... My combobox is connected on my database. my code:

public partial class Form2 : Form
{
    public string myConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Bojan\Desktop\Programiranje\School\Novo\Novo\Ure.accdb";  // to je provider za Access 2007 in vec - ce ga ni na lokalni mašini ga je treba namestiti!!!

    public Form2()
    {
        InitializeComponent();
    }

    private void Form2_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'dataSet1.Ure' table. You can move, or remove it, as needed.
        this.ureTableAdapter.Fill(this.dataSet1.Ure);
    }

    private void Brisanje_Click(object sender, EventArgs e)
    {
        OleDbConnection myConnection = null;

        myConnection = new OleDbConnection();                      // kreiranje konekcije
        myConnection.ConnectionString = myConnectionString;
        myConnection.Open();

        OleDbCommand cmd = myConnection.CreateCommand();
        cmd.Connection = myConnection;
        cmd.CommandText = "DELETE FROM Ure WHERE (ID) = '"+Izbor.SelectedValue+"'";
        cmd.ExecuteNonQuery();
        cmd.Prepare();
        myConnection.Close();
    }
}

Thanks for your help

© Stack Overflow or respective owner

Related posts about c#