editing records with a datagrid

biscuitbandit

Newcomer
Joined
Apr 5, 2004
Messages
2
Never mind, i forgot to put "If Not Page.IsPostBack Then" on the page load section, so its sorted.

hi all,

i have a table in an access database like so
tbl_link(linkid, linkname, link)

im currently trying to get a datagrid to work so i can edit the records but i've run into a bit of trouble. the datagrid looks like this
Code:
        <asp:DataGrid id="LinkGrid" runat="server" OnEditCommand="EditRecord" OnUpdateCommand="UpdateRecord" OnCancelCommand="CancelRecord" AutoGenerateColumns="False">
            <Columns>
                <asp:BoundColumn HeaderText="LinkID" DataField="linkid" />
                <asp:BoundColumn HeaderText="Link Name" DataField="linkname" />
                <asp:BoundColumn HeaderText="Actual Link" DataField="link" />
                <asp:EditCommandColumn HeaderText="Editing" EditText="Edit" UpdateText="Update" CancelText="Cancel" />
            </Columns>
        </asp:DataGrid>

the problem im having is that records wont update at all and im pretty positive that its due to the ID column being the wrong value but i can't work out how to sort the problem.

the rest of the code is like this
Code:
  Dim DBConnection As OleDbConnection
  Dim DBCommand As OleDbCommand
  Dim DBReader As OleDbDataReader
  Dim SQLString As String

Sub Page_Load
    BindDataGrid
End Sub

Sub BindDataGrid

  'get all the data

End Sub

Sub EditRecord (Src As Object, Args As DataGridCommandEventArgs)
  LinkGrid.EditItemIndex = Args.Item.ItemIndex
  BindDataGrid
End Sub

Sub UpdateRecord  (Src As Object, Args As DataGridCommandEventArgs)

  Dim linkid = CType(Args.Item.Cells(0).Controls(0), TextBox).Text
  Dim linkname = CType(Args.Item.Cells(1).Controls(0), TextBox).Text
  Dim link = CType(Args.Item.Cells(2).Controls(0), TextBox).Text

  SQLString = "UPDATE tbl_link SET " & _
    "linkname = '" & linkname & "', " & _
    "link = '" & link & "' " & _
    "WHERE linkid = " & linkid

  DBConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\inetpub\db\bedb_las.mdb")
  DBConnection.Open()
  DBCommand = New OleDbCommand(SQLString, DBConnection)
  DBCommand.ExecuteNonQuery()
  DBConnection.Close()

  LinkGrid.EditItemIndex = -1
  BindDataGrid

End Sub

Sub CancelRecord  (Src As Object, Args As DataGridCommandEventArgs)
  LinkGrid.EditItemIndex = -1
  BindDataGrid
End Sub

any ideas please,

-bb
 
Last edited:
Back
Top