How to programmatically set the text of a cell of database in VB.Net?
- by manuel
I have a Microsoft Access database file connected to VB.NET.
In the database table, I have a 'No.' and a 'Status' column.
Then I have a textbox where I can input an integer.
I also have a button, which will change the data cell in 'Status' where 'No.' = txtTitleNo.Text(), when I click it.
Let's say I want the 'Status' cell to be changed to "Reserved".
What codes should I put in the BtnReserve_Click?
Here is the code:
Public Class theForm
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim daTitles As OleDb.OleDbDataAdapter
Private Sub theForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|\db1.mdb"
con.Open()
daTitles = New OleDb.OleDbDataAdapter("SELECT * FROM Titles", con)
daTitles.Fill(ds, "Titles")
DataGridView1.DataSource = ds.Tables("Titles")
DataGridView1.AutoResizeColumns()
End Sub
Private Sub BtnReserve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnReserve.Click
Dim daReserve As OleDb.OleDbCommand
For i As Integer = 1 TReservedo DataGridView1.RowCount()
If i = Val(txtTitleNo.Text()) Then
daReserve = New OleDb.OleDbCommand("UPDATE Titles SET Status = 'Reserved' WHERE No = '" & i & "'", con)
daReserve.ExecuteNonQuery()
End If
Next
Dim cb As New OleDb.OleDbCommandBuilder(daTitles)
daTitles.Update(ds, "Titles")
End Sub
This code still does not change the 'Status'. What should I do?