none
Update query in MS Access using C#

    Question

  • IM writing an update query to update my MS Access database using C#. It looks like I have all the syntax correct, but IM not sure. It is my first time writing a parameterized query. WHen I run it, it gives no errors and the software doesnt even hiccup, but the database doesnt update.

                    //Update Work Order tabs
                    string strSql = "UPDATE tblWO SET JobKey = @JobKey, BudgetNum = @BudgetNum, SubLedger = "
                        + "@SubLedger, WorkOrder = @WorkOrder, MatCosts = @MatCosts, LabCosts = @LabCosts,"
                        + "LabHrs = @LabHrs, EngCosts = @EngCosts WHERE WOKey = @WOKey";
                    DBResConn.Open();
                    OleDbCommand upWO = new OleDbCommand(strSql, DBResConn);
                    upWO.CommandType = CommandType.Text;
                    upWO.Parameters.AddWithValue("JobKey", jobKey);
                    upWO.Parameters.AddWithValue("BudgetNum", tbBudNum.Text);
                    upWO.Parameters.AddWithValue("SubLedger",  tbSubLed.Text);
                    upWO.Parameters.AddWithValue("WorkOrder", tbWorOrd.Text);
                    upWO.Parameters.AddWithValue("MatCosts", tbMatCosts.Text);
                    upWO.Parameters.AddWithValue("LabCosts", tbLabCosts.Text);
                    upWO.Parameters.AddWithValue("LabHrs", tbLabHrs.Text);
                    upWO.Parameters.AddWithValue("EngCosts", tbEngCosts.Text);
                    upWO.Parameters.AddWithValue("WOKey", WOKey.ToString());
                        
                    upWO.ExecuteNonQuery();
                    DBResConn.Close();
    I know I have a valid value in the WOKey, i put an xtra textbox on the screen just to show it before performing the update. Anyone see anything wrong here?
    Saturday, January 09, 2010 1:58 PM

Answers

  • This is a SQL Server forums not MS Access. Your question is pertaining to ADO.net rather MS Access

    What value is returned by  upWO.ExecuteNonQuery();

    It should return an integer -- number of rows affected by your update; if it returns -1 then  most likely you have error in your SQL statement i.e. strSQL

    Saturday, January 09, 2010 3:31 PM