how to update a table in c# using oledb parameters?

Posted by sameer on Stack Overflow See other posts from Stack Overflow or by sameer
Published on 2010-04-20T13:51:04Z Indexed on 2010/04/20 13:53 UTC
Read the original article Hit count: 226

Filed under:

I am having a table which has three fields, namely LM_code,M_Name,Desc. LC_code is a autogenerated string Id, keeping this i am updating M_Name and Desc. I used normal update command, the value is passing in runtime but the fields are not getting updated. I hope using oledb parameters the fileds can be updated.

Any help will be appreciated...

Here is my code.

public void Modify() { String query = "Update Master_Accounts set (M_Name='" + M_Name + "',Desc='" + Desc + "') where LM_code='" + LM_code + "'"; DataManager.RunExecuteNonQuery(ConnectionString.Constr, query); }

In DataManager Class i am executing the query string.

public static void RunExecuteNonQuery(string Constr, string query) {

        OleDbConnection myConnection = new OleDbConnection(Constr);
        try
        {
            myConnection.Open();
            OleDbCommand myCommand = new OleDbCommand(query, myConnection);
            myCommand.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            string Message = ex.Message;
            throw ex;
        }

        finally
        {
            if (myConnection.State == ConnectionState.Open)
                myConnection.Close();
        }

    }

private void toolstModify_Click_1(object sender, EventArgs e) { txtamcode.Enabled = true; jewellery.LM_code = txtamcode.Text; jewellery.M_Name = txtaccname.Text; jewellery.Desc = txtdesc.Text; jewellery.Modify(); MessageBox.Show("Data Updated Succesfully");

    }

© Stack Overflow or respective owner

Related posts about c#