locked
Update query always returns 0 access database RRS feed

  • Question

  • User1231667415 posted

    Hi,

    I am trying to update records but getting 0 rows effected returned all the time. Initially I was getting error when trying to insert or update null values. After I got that fixed this new problem arised. My query runs fine if I try to execute that directly against the table.

    Here is my code

    public bool UpdateRecord()
            {
                bool isOK = true;
                using (OleDbConnection oCon = new OleDbConnection(connectionString))
                {
    
                    string sqlUpdate = @"UPDATE Table SET ROUTING_NUMBER = @ROUTING_NUMBER, VALIDITY_DATE = @VALIDITY_DATE WHERE (ID = @ID)";
                    try
                    {
                        
                            OleDbCommand oCmd = new OleDbCommand(sqlUpdate, oCon);
                            
                            oCon.Open();
    
                           
                            oCmd.Parameters.AddWithValue("@ROUTING_NUMBER", ROUTING_NO);
                            oCmd.Parameters.AddWithValue("@VALIDITY_DATE", VALIDITY_DATE_STRING);
                            
                            oCmd.Parameters.AddWithValue("@ID", ID);
                        
                            int i = oCmd.ExecuteNonQuery();
                            if (i > 0)
                                isOK = true;
                            else
                                isOK = false;
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally { oCon.Close(); }
                }
    
                return isOK;

    Friday, September 16, 2011 12:58 AM

Answers

  • User1231667415 posted

    Got that fixed. Not sure if this is the perfect solution but its working.

    Just use update query like

    UPDATE Global_Routing_Guide SET ROUTING_NUMBER =?, VALIDITY_DATE =?, SHIP_FROM_CITY =?, SHIP_FROM_STATE =?,
                           where ID=?"

    The "?" solved my problem.

    Regards

    Vijay Vishwakarma

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 16, 2011 1:21 AM
  • User-1199946673 posted

    The "?" solved my problem.

    No you can use ? or named parameters!

    Could it be you mispelled 1 or more fieldnames in your query, for example:

    [TRANSIT_TIME_OCEAN_LCL__BUYERS CONSOL]

    Instead of

    [TRANSIT_TIME_OCEAN_LCL_BUYERS CONSOL]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 16, 2011 2:55 AM

All replies

  • User1231667415 posted

    Got that fixed. Not sure if this is the perfect solution but its working.

    Just use update query like

    UPDATE Global_Routing_Guide SET ROUTING_NUMBER =?, VALIDITY_DATE =?, SHIP_FROM_CITY =?, SHIP_FROM_STATE =?,
                           where ID=?"

    The "?" solved my problem.

    Regards

    Vijay Vishwakarma

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 16, 2011 1:21 AM
  • User-1199946673 posted

    The "?" solved my problem.

    No you can use ? or named parameters!

    Could it be you mispelled 1 or more fieldnames in your query, for example:

    [TRANSIT_TIME_OCEAN_LCL__BUYERS CONSOL]

    Instead of

    [TRANSIT_TIME_OCEAN_LCL_BUYERS CONSOL]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 16, 2011 2:55 AM
  • User1231667415 posted

    Yes, you are right hans_v.

    Wednesday, January 18, 2012 3:31 AM