So far I can compute and update seperately a specific row when type it in a text box. What I want now is to read and update rows automatically up until the last record.
Imports System.Data.OleDb
Public Class Form1
Dim MyConnection As New OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0; Data Source=G:\Raw Data.xlsx; Extended Properties=Excel 12.0;")
Dim DtSet As DataSet
Dim myCommand As OleDbDataAdapter
Dim myCommandsql As OleDbCommand
Dim sql As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String
s = TextBox1.Text
Dim i, cs, digit As Integer
cs = 0 'checksum
For i = 1 To 12
digit = Mid(s, i, 1) - "0"
If i Mod 2 = 0 Then
cs = cs + digit * 3
Else
cs = cs + digit * 1
End If
Next i
cs = (10 - (cs Mod 10)) Mod 10
TextBox2.Text = s & cs
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Try
MyConnection.Open()
myCommand = New OleDbDataAdapter _
("select * from [Sheet1$]", MyConnection)
'myCommand.TableMappings.Add("Table", "TestTable")
DtSet = New DataSet
myCommand.Fill(DtSet)
DataGridView1.DataSource = DtSet.Tables(0)
MyConnection.Close()
'Catch ex As Exception
'MsgBox(ex.ToString)
'End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'Try
MyConnection.Open()
sql = "Update [Sheet1$] set BARCODE = '" & TextBox2.Text & "' Where RAW = '" & TextBox1.Text & "'"
myCommandsql = New OleDbCommand(sql, MyConnection)
'myCommandsql.CommandText = sql
myCommandsql.ExecuteNonQuery()
myCommand = New OleDbDataAdapter _
("select * from [Sheet1$]", MyConnection)
DtSet = New DataSet
myCommand.Fill(DtSet)
DataGridView1.DataSource = DtSet.Tables(0)
MyConnection.Close()
'Catch ex As Exception
' MsgBox(ex.ToString)
'End Try
MsgBox("Updated ")
End Sub
End Class
Disregard the DataGrid. Thanks