Hello, im working on a project that works with an access database but i dont know how to edit an existing record...
here is the code that i use for reading the database:
Public Function ask()
Dim dt As New DataTable
Dim ds As New DataSet
ds.Tables.Add(dt)
con.Open()
Dim da As New OleDbDataAdapter("select * from data", con)
da.Fill(dt)
Dim newRow As DataRow = dt.NewRow
For Each DataRow In dt.Rows
If CardID.Text = DataRow.Item(0) Then
usrname = DataRow.Item(1)
cardv = DataRow.Item(0)
usrid = DataRow.Item(2)
log2.DataSource = dt.DefaultView
DataRow.Item("card") = cardv
'dt.Rows.Add(newRow)
Dim cb As New OleDbCommandBuilder(da)
log.DataSource = dt.DefaultView
da.Update(dt)
Return True
Else
End If
Next
con.Close()
Return False
End Function
Here is the code i used to add a new record:
con.Open()
Dim dt As New DataTable
Dim ds As New DataSet
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter("select * from data", con)
da.Fill(dt)
Dim newRow As DataRow = dt.NewRow
With newRow
.Item("card") = cardtxt.Text
.Item("name") = nametxt.Text
.Item("id") = idtxt.Text
.Item("in") = ComboBox1.Text
End With
dt.Rows.Add(newRow)
Dim cb As New OleDbCommandBuilder(da)
da.Update(dt)
DataGridView1.DataSource = dt.DefaultView
con.Close()
cardtxt.Clear()
nametxt.Clear()
idtxt.Clear()
cardtxt.Select()
now, both of those codes work just fine(I know you will say there is an easier way to use access, but trust me, i need it this way).
So how could i edit an existing record?