Update from datagrid

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Update from datagrid

    I am currently learning asp.net (vb) with Web Matrix. I am building an
    intranet page that will have an editable datagrid on it. I have got the
    datagrid to populate OK but I cannot get the Update method to work
    correctly.

    I click on edit and and the non-readonly field become editable as in
    [url]http://www.russgreen.net/software/newsgroupimages/screenshot1.gif[/url]
    The update button does nothing. See
    [url]http://www.russgreen.net/software/newsgroupimages/screenshot2.gif[/url]

    Error page
    [url]http://www.russgreen.net/software/newsgroupimages/SyntaxerrorinUPDATEstateme[/url]
    nt_.htm
    ..aspx page
    [url]http://www.russgreen.net/software/newsgroupimages/db_project_list_new.aspx[/url]

    Can someone please help explain this please?

    Sub DataGrid_Update(s As Object, e As DataGridCommandEventArgs )
    'create edit text boxes
    Dim txtName As textbox = E.Item.cells(2).Controls(0)
    Dim txtStatus As textbox = E.Item.cells(3).Controls(0)
    Dim txtAction As textbox = E.Item.cells(4).Controls(0)
    Dim txtStaff As textbox = E.Item.cells(5).Controls(0)

    'update SQL
    Dim strUpdateSql As String ="UPDATE Projects SET" & _
    " Name =@Name, Status =@Status, Action = @Action, Staff = @Staff" &
    _
    " WHERE ProjectID = @ProjectID"

    'connection stuff
    Dim conn As OleDbConnection = New OleDbConnection(strConn)
    conn.Open()

    'command Object to Execute the SQL
    Dim cmd As OleDbCommand = New OleDbCommand(strUpdateSql, conn)
    cmd.Parameters.Add(New OleDbParameter("@Name", txtName.text))
    cmd.Parameters.Add(New OleDbParameter("@Status", txtStatus.text))
    cmd.Parameters.Add(New OleDbParameter("@Action", txtAction.text))
    cmd.Parameters.Add(New OleDbParameter("@Staff", txtStaff.text))
    cmd.Parameters.Add(New OleDbParameter("@ProjectID",
    CType(e.Item.Cells(0).Text, Long)))
    cmd.ExecuteNonQuery()

    'do housekeeping
    DataGrid1.EditItemIndex = -1
    conn.close

    'rebind
    BindData()
    End Sub


    Russ Green Guest

  2. Similar Questions and Discussions

    1. How to add a Dropdown list to a datagrid at runtime (dynamic) without using template columns in ASP.NET and still have the ability to us the datagrid Update event.
      How to add a Dropdown list to a datagrid at runtime (dynamic) without using template columns in ASP.NET and still have the ability to us the...
    2. DataGrid ItemStyle is a textbox and doesn't update the datagrid datasource
      I have a datagrid with two columns, the first a normal bound column, the second is a template column created from a bound column. For the...
    3. DataGrid easy Edit-Update using ADO.NET/DataGrid functionality C#?
      Hi, so I am using built in Edit, Delete, Update i.e. OnEditCommand="DataGrid1_Edit" OnUpdateCommand="DataGrid1_Update" with handler question below...
    4. Can't update in DataGrid
      I have looked at all the examples and written a datagrid page with update features, but the update doesn't work. Basically, it never executes the...
    5. To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible?
      Hello, I am searching the whole Internet for a good example how to edit/update a DataGrid in a DataGrid (nested DataGrid). I know how to...
  3. #2

    Default Re: Update from datagrid

    Hi Russ,

    You need to use the last parameter @product ID

    cmd.Parameters.Add(New OleDbParameter("@ProjectID",
    DataGrid1.DataKeys(e.Item.ItemIndex))

    It's interesting your sub is

    DataGrid_Update but the ID of the object seems to be DataGrid1. I would have
    expected DataGrid1_UpdateCommand but I suppose that could just be the way
    that datamatrix wires it up. Then again... perhaps I'm wrong.

    "Russ Green" <russgreen249@hotmail.com> wrote in message
    news:ew3e7tuTDHA.1740@TK2MSFTNGP12.phx.gbl...
    > I am currently learning asp.net (vb) with Web Matrix. I am building an
    > intranet page that will have an editable datagrid on it. I have got the
    > datagrid to populate OK but I cannot get the Update method to work
    > correctly.
    >
    > I click on edit and and the non-readonly field become editable as in
    > [url]http://www.russgreen.net/software/newsgroupimages/screenshot1.gif[/url]
    > The update button does nothing. See
    > [url]http://www.russgreen.net/software/newsgroupimages/screenshot2.gif[/url]
    >
    > Error page
    >
    [url]http://www.russgreen.net/software/newsgroupimages/SyntaxerrorinUPDATEstateme[/url]
    > nt_.htm
    > .aspx page
    > [url]http://www.russgreen.net/software/newsgroupimages/db_project_list_new.aspx[/url]
    >
    > Can someone please help explain this please?
    >
    > Sub DataGrid_Update(s As Object, e As DataGridCommandEventArgs )
    > 'create edit text boxes
    > Dim txtName As textbox = E.Item.cells(2).Controls(0)
    > Dim txtStatus As textbox = E.Item.cells(3).Controls(0)
    > Dim txtAction As textbox = E.Item.cells(4).Controls(0)
    > Dim txtStaff As textbox = E.Item.cells(5).Controls(0)
    >
    > 'update SQL
    > Dim strUpdateSql As String ="UPDATE Projects SET" & _
    > " Name =@Name, Status =@Status, Action = @Action, Staff = @Staff"
    &
    > _
    > " WHERE ProjectID = @ProjectID"
    >
    > 'connection stuff
    > Dim conn As OleDbConnection = New OleDbConnection(strConn)
    > conn.Open()
    >
    > 'command Object to Execute the SQL
    > Dim cmd As OleDbCommand = New OleDbCommand(strUpdateSql, conn)
    > cmd.Parameters.Add(New OleDbParameter("@Name", txtName.text))
    > cmd.Parameters.Add(New OleDbParameter("@Status", txtStatus.text))
    > cmd.Parameters.Add(New OleDbParameter("@Action", txtAction.text))
    > cmd.Parameters.Add(New OleDbParameter("@Staff", txtStaff.text))
    > cmd.Parameters.Add(New OleDbParameter("@ProjectID",
    > CType(e.Item.Cells(0).Text, Long)))
    > cmd.ExecuteNonQuery()
    >
    > 'do housekeeping
    > DataGrid1.EditItemIndex = -1
    > conn.close
    >
    > 'rebind
    > BindData()
    > End Sub
    >
    >

    John Toop Guest

  4. #3

    Default Re: Update from datagrid

    OK

    I sorted it. Well almost. The attached page works on the Webmatrix testing
    server but not on IIS. Under IIS the page render OK but UPDATE generate the
    following exception: -

    System.Data.OleDb.OleDbException: Operation must use an updateable query. at
    System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr) at
    System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
    dbParams, Object& executeResult) at
    System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult) at
    System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior,
    Object& executeResult) at
    System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior
    behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
    at ASP.db_project_list_aspx.DataGrid_Update(Object s,
    DataGridCommandEventArgs e) in D:\Web Design
    Work\SALT_INTRANET\asp_net\db_project_list.aspx:li ne 68

    Any Ideas?

    Russ

    "John Toop" <jtoop@rogers.com> wrote in message
    news:e$vpnGzTDHA.1724@TK2MSFTNGP10.phx.gbl...
    > Hi Russ,
    >
    > You need to use the last parameter @product ID
    >
    > cmd.Parameters.Add(New OleDbParameter("@ProjectID",
    > DataGrid1.DataKeys(e.Item.ItemIndex))
    >
    > It's interesting your sub is
    >
    > DataGrid_Update but the ID of the object seems to be DataGrid1. I would
    have
    > expected DataGrid1_UpdateCommand but I suppose that could just be the way
    > that datamatrix wires it up. Then again... perhaps I'm wrong.
    >
    > "Russ Green" <russgreen249@hotmail.com> wrote in message
    > news:ew3e7tuTDHA.1740@TK2MSFTNGP12.phx.gbl...
    > > I am currently learning asp.net (vb) with Web Matrix. I am building an
    > > intranet page that will have an editable datagrid on it. I have got the
    > > datagrid to populate OK but I cannot get the Update method to work
    > > correctly.
    > >
    > > I click on edit and and the non-readonly field become editable as in
    > > [url]http://www.russgreen.net/software/newsgroupimages/screenshot1.gif[/url]
    > > The update button does nothing. See
    > > [url]http://www.russgreen.net/software/newsgroupimages/screenshot2.gif[/url]
    > >
    > > Error page
    > >
    >
    [url]http://www.russgreen.net/software/newsgroupimages/SyntaxerrorinUPDATEstateme[/url]
    > > nt_.htm
    > > .aspx page
    > >
    [url]http://www.russgreen.net/software/newsgroupimages/db_project_list_new.aspx[/url]
    > >
    > > Can someone please help explain this please?
    > >
    > > Sub DataGrid_Update(s As Object, e As DataGridCommandEventArgs )
    > > 'create edit text boxes
    > > Dim txtName As textbox = E.Item.cells(2).Controls(0)
    > > Dim txtStatus As textbox = E.Item.cells(3).Controls(0)
    > > Dim txtAction As textbox = E.Item.cells(4).Controls(0)
    > > Dim txtStaff As textbox = E.Item.cells(5).Controls(0)
    > >
    > > 'update SQL
    > > Dim strUpdateSql As String ="UPDATE Projects SET" & _
    > > " Name =@Name, Status =@Status, Action = @Action, Staff =
    @Staff"
    > &
    > > _
    > > " WHERE ProjectID = @ProjectID"
    > >
    > > 'connection stuff
    > > Dim conn As OleDbConnection = New OleDbConnection(strConn)
    > > conn.Open()
    > >
    > > 'command Object to Execute the SQL
    > > Dim cmd As OleDbCommand = New OleDbCommand(strUpdateSql, conn)
    > > cmd.Parameters.Add(New OleDbParameter("@Name", txtName.text))
    > > cmd.Parameters.Add(New OleDbParameter("@Status", txtStatus.text))
    > > cmd.Parameters.Add(New OleDbParameter("@Action", txtAction.text))
    > > cmd.Parameters.Add(New OleDbParameter("@Staff", txtStaff.text))
    > > cmd.Parameters.Add(New OleDbParameter("@ProjectID",
    > > CType(e.Item.Cells(0).Text, Long)))
    > > cmd.ExecuteNonQuery()
    > >
    > > 'do housekeeping
    > > DataGrid1.EditItemIndex = -1
    > > conn.close
    > >
    > > 'rebind
    > > BindData()
    > > End Sub
    > >
    > >
    >
    >

    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    Version: 6.0.500 / Virus Database: 298 - Release Date: 10/07/2003




    Russ Green Guest

  5. #4

    Default Re: Update from datagrid

    Hi Russ,
    you are getting this error "Operation must use an updateable query" may for two reasons...
    1. Folder where you are having MDB file doesnot have permission for your asp.net applications.
    2. Give the permission for MDB file.

    Rajeev

    "Russ Green" <russgreen249@hotmail.com> wrote in message news:ul4buYIUDHA.2308@TK2MSFTNGP12.phx.gbl...
    > OK
    >
    > I sorted it. Well almost. The attached page works on the Webmatrix testing
    > server but not on IIS. Under IIS the page render OK but UPDATE generate the
    > following exception: -
    >
    > System.Data.OleDb.OleDbException: Operation must use an updateable query. at
    > System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr) at
    > System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
    > dbParams, Object& executeResult) at
    > System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult) at
    > System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior,
    > Object& executeResult) at
    > System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior
    > behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
    > at ASP.db_project_list_aspx.DataGrid_Update(Object s,
    > DataGridCommandEventArgs e) in D:\Web Design
    > Work\SALT_INTRANET\asp_net\db_project_list.aspx:li ne 68
    >
    > Any Ideas?
    >
    > Russ
    >
    > "John Toop" <jtoop@rogers.com> wrote in message
    > news:e$vpnGzTDHA.1724@TK2MSFTNGP10.phx.gbl...
    > > Hi Russ,
    > >
    > > You need to use the last parameter @product ID
    > >
    > > cmd.Parameters.Add(New OleDbParameter("@ProjectID",
    > > DataGrid1.DataKeys(e.Item.ItemIndex))
    > >
    > > It's interesting your sub is
    > >
    > > DataGrid_Update but the ID of the object seems to be DataGrid1. I would
    > have
    > > expected DataGrid1_UpdateCommand but I suppose that could just be the way
    > > that datamatrix wires it up. Then again... perhaps I'm wrong.
    > >
    > > "Russ Green" <russgreen249@hotmail.com> wrote in message
    > > news:ew3e7tuTDHA.1740@TK2MSFTNGP12.phx.gbl...
    > > > I am currently learning asp.net (vb) with Web Matrix. I am building an
    > > > intranet page that will have an editable datagrid on it. I have got the
    > > > datagrid to populate OK but I cannot get the Update method to work
    > > > correctly.
    > > >
    > > > I click on edit and and the non-readonly field become editable as in
    > > > [url]http://www.russgreen.net/software/newsgroupimages/screenshot1.gif[/url]
    > > > The update button does nothing. See
    > > > [url]http://www.russgreen.net/software/newsgroupimages/screenshot2.gif[/url]
    > > >
    > > > Error page
    > > >
    > >
    > [url]http://www.russgreen.net/software/newsgroupimages/SyntaxerrorinUPDATEstateme[/url]
    > > > nt_.htm
    > > > .aspx page
    > > >
    > [url]http://www.russgreen.net/software/newsgroupimages/db_project_list_new.aspx[/url]
    > > >
    > > > Can someone please help explain this please?
    > > >
    > > > Sub DataGrid_Update(s As Object, e As DataGridCommandEventArgs )
    > > > 'create edit text boxes
    > > > Dim txtName As textbox = E.Item.cells(2).Controls(0)
    > > > Dim txtStatus As textbox = E.Item.cells(3).Controls(0)
    > > > Dim txtAction As textbox = E.Item.cells(4).Controls(0)
    > > > Dim txtStaff As textbox = E.Item.cells(5).Controls(0)
    > > >
    > > > 'update SQL
    > > > Dim strUpdateSql As String ="UPDATE Projects SET" & _
    > > > " Name =@Name, Status =@Status, Action = @Action, Staff =
    > @Staff"
    > > &
    > > > _
    > > > " WHERE ProjectID = @ProjectID"
    > > >
    > > > 'connection stuff
    > > > Dim conn As OleDbConnection = New OleDbConnection(strConn)
    > > > conn.Open()
    > > >
    > > > 'command Object to Execute the SQL
    > > > Dim cmd As OleDbCommand = New OleDbCommand(strUpdateSql, conn)
    > > > cmd.Parameters.Add(New OleDbParameter("@Name", txtName.text))
    > > > cmd.Parameters.Add(New OleDbParameter("@Status", txtStatus.text))
    > > > cmd.Parameters.Add(New OleDbParameter("@Action", txtAction.text))
    > > > cmd.Parameters.Add(New OleDbParameter("@Staff", txtStaff.text))
    > > > cmd.Parameters.Add(New OleDbParameter("@ProjectID",
    > > > CType(e.Item.Cells(0).Text, Long)))
    > > > cmd.ExecuteNonQuery()
    > > >
    > > > 'do housekeeping
    > > > DataGrid1.EditItemIndex = -1
    > > > conn.close
    > > >
    > > > 'rebind
    > > > BindData()
    > > > End Sub
    > > >
    > > >
    > >
    > >
    >
    >
    > ---
    > Outgoing mail is certified Virus Free.
    > Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    > Version: 6.0.500 / Virus Database: 298 - Release Date: 10/07/2003
    >
    >
    >
    Rajeev Soni Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139