Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Update a record in a database via a datagrid

Update a record in a database via a datagrid

Scheduled Pinned Locked Moved ASP.NET
databasehelpannouncement
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AesopTurtle
    wrote on last edited by
    #1

    I'm trying to make an update to a record in a MS Access database via a datagrid edit column. When i press the update button, an error occurs: System.Data.OleDb.OleDbException: Operation must use an updateable query. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at RuamSiam.editsalerate.dgSaleRate_Update(Object sender, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\ruamsiam\editsalerate.aspx.cs:line 187 Here's the sql used for this update: (generated by my app) update salerate set cashprice = '29000',financeprice = '25000',downpayment = '1500',cost = '28900' where model = 'AN112A' The columns in the datagrid consist of the following: [0]: model: Button Column [1]: cashprice: Bound Column [2]: financeprice: Bound Column [3]: downpayment: Bound Column [4]: cost: Bound Column [5]: Edit,Update,Cancel: Button Column [6]: Delete: Button Column The code i use for the update process is: TextBox cashprice,financeprice,downpayment,cost; string model = this.dgSaleRate.DataKeys[this.dgSaleRate.SelectedIndex].ToString(); cashprice = (TextBox)e.Item.Cells[1].Controls[0]; financeprice = (TextBox)e.Item.Cells[2].Controls[0]; downpayment = (TextBox)e.Item.Cells[3].Controls[0]; cost = (TextBox)e.Item.Cells[4].Controls[0]; string sqlUpdate = "update salerate set "; sqlUpdate += "cashprice = '" + cashprice.Text + "',"; sqlUpdate += "financeprice = '" + financeprice.Text + "',"; sqlUpdate += "downpayment = '" + downpayment.Text + "',"; sqlUpdate += "cost = '" + cost.Text + "'"; sqlUpdate += " where model = '" + model + "'"; try { if(conn.State == ConnectionState.Open) { conn.Close(); } conn.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = conn; //the connection is connected correctly. cmd.CommandType = CommandType.Text; cmd.CommandText = sqlUpdate; cmd.ExecuteNonQuery(); } catch(Exception ex) { this.lblErrMsg.Text = ex.ToString(); this.lblErrMsg.Text += "<br><br>" + sqlUpdate; } finally { this.

    P M 2 Replies Last reply
    0
    • A AesopTurtle

      I'm trying to make an update to a record in a MS Access database via a datagrid edit column. When i press the update button, an error occurs: System.Data.OleDb.OleDbException: Operation must use an updateable query. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at RuamSiam.editsalerate.dgSaleRate_Update(Object sender, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\ruamsiam\editsalerate.aspx.cs:line 187 Here's the sql used for this update: (generated by my app) update salerate set cashprice = '29000',financeprice = '25000',downpayment = '1500',cost = '28900' where model = 'AN112A' The columns in the datagrid consist of the following: [0]: model: Button Column [1]: cashprice: Bound Column [2]: financeprice: Bound Column [3]: downpayment: Bound Column [4]: cost: Bound Column [5]: Edit,Update,Cancel: Button Column [6]: Delete: Button Column The code i use for the update process is: TextBox cashprice,financeprice,downpayment,cost; string model = this.dgSaleRate.DataKeys[this.dgSaleRate.SelectedIndex].ToString(); cashprice = (TextBox)e.Item.Cells[1].Controls[0]; financeprice = (TextBox)e.Item.Cells[2].Controls[0]; downpayment = (TextBox)e.Item.Cells[3].Controls[0]; cost = (TextBox)e.Item.Cells[4].Controls[0]; string sqlUpdate = "update salerate set "; sqlUpdate += "cashprice = '" + cashprice.Text + "',"; sqlUpdate += "financeprice = '" + financeprice.Text + "',"; sqlUpdate += "downpayment = '" + downpayment.Text + "',"; sqlUpdate += "cost = '" + cost.Text + "'"; sqlUpdate += " where model = '" + model + "'"; try { if(conn.State == ConnectionState.Open) { conn.Close(); } conn.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = conn; //the connection is connected correctly. cmd.CommandType = CommandType.Text; cmd.CommandText = sqlUpdate; cmd.ExecuteNonQuery(); } catch(Exception ex) { this.lblErrMsg.Text = ex.ToString(); this.lblErrMsg.Text += "<br><br>" + sqlUpdate; } finally { this.

      P Offline
      P Offline
      padvit
      wrote on last edited by
      #2

      At first glance I feel there datatype mismatch happening, Closely watch the values passed and datatypes may be you will be able to trace out Padvit

      A 1 Reply Last reply
      0
      • P padvit

        At first glance I feel there datatype mismatch happening, Closely watch the values passed and datatypes may be you will be able to trace out Padvit

        A Offline
        A Offline
        AesopTurtle
        wrote on last edited by
        #3

        I've tried changing the datatype but it still doesn't work and yields the same error. Thank you so much anyway. KiT

        1 Reply Last reply
        0
        • A AesopTurtle

          I'm trying to make an update to a record in a MS Access database via a datagrid edit column. When i press the update button, an error occurs: System.Data.OleDb.OleDbException: Operation must use an updateable query. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at RuamSiam.editsalerate.dgSaleRate_Update(Object sender, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\ruamsiam\editsalerate.aspx.cs:line 187 Here's the sql used for this update: (generated by my app) update salerate set cashprice = '29000',financeprice = '25000',downpayment = '1500',cost = '28900' where model = 'AN112A' The columns in the datagrid consist of the following: [0]: model: Button Column [1]: cashprice: Bound Column [2]: financeprice: Bound Column [3]: downpayment: Bound Column [4]: cost: Bound Column [5]: Edit,Update,Cancel: Button Column [6]: Delete: Button Column The code i use for the update process is: TextBox cashprice,financeprice,downpayment,cost; string model = this.dgSaleRate.DataKeys[this.dgSaleRate.SelectedIndex].ToString(); cashprice = (TextBox)e.Item.Cells[1].Controls[0]; financeprice = (TextBox)e.Item.Cells[2].Controls[0]; downpayment = (TextBox)e.Item.Cells[3].Controls[0]; cost = (TextBox)e.Item.Cells[4].Controls[0]; string sqlUpdate = "update salerate set "; sqlUpdate += "cashprice = '" + cashprice.Text + "',"; sqlUpdate += "financeprice = '" + financeprice.Text + "',"; sqlUpdate += "downpayment = '" + downpayment.Text + "',"; sqlUpdate += "cost = '" + cost.Text + "'"; sqlUpdate += " where model = '" + model + "'"; try { if(conn.State == ConnectionState.Open) { conn.Close(); } conn.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = conn; //the connection is connected correctly. cmd.CommandType = CommandType.Text; cmd.CommandText = sqlUpdate; cmd.ExecuteNonQuery(); } catch(Exception ex) { this.lblErrMsg.Text = ex.ToString(); this.lblErrMsg.Text += "<br><br>" + sqlUpdate; } finally { this.

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Hi there, Make sure the ASP.NET process identity has the modify permission to the folder containing the database file .mdb

          A 1 Reply Last reply
          0
          • M minhpc_bk

            Hi there, Make sure the ASP.NET process identity has the modify permission to the folder containing the database file .mdb

            A Offline
            A Offline
            AesopTurtle
            wrote on last edited by
            #5

            Oops... How could i forget such a simple thing...:-D silly me. It's working now. Thank you so much. KiT

            M 1 Reply Last reply
            0
            • A AesopTurtle

              Oops... How could i forget such a simple thing...:-D silly me. It's working now. Thank you so much. KiT

              M Offline
              M Offline
              minhpc_bk
              wrote on last edited by
              #6

              We sometimes need to forget simple things so that we can spend our memory for more complicated issues. :-D

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups