i wanted to update excelsheet dynamically how can i do using excelsheet vba to mysql PLEASE HELP ME OUT I AM STUCK HERE
i hve downloaded data from batchname(tblprod_agr_007) in excelsheet from mysql database its starts with column name WDS_id
what ever i edit in that data(excelsheet) it should be update into mysql database
i hve downloaded data from batchname(tblprod_agr_007) in excelsheet from mysql database its starts with column name WDS_id
what ever i edit in that data(excelsheet) it should be update into mysql database
Code:
Dim rst1 As ADODB.Recordset, rst2 As ADODB.Recordset
Dim stDB As String, stSQL1 As String, stSQL2 As String
Dim strConn As String
Dim wbBook As Workbook
Dim Sheet1 As Worksheet
Dim i, prBatchName, totColumns, totRows, j, WDS_id
Dim lnField As Long, lnCount As Long
Dim dataStr As String
'Instantiate the ADO-objects.
Set cnt = New ADODB.Connection
' Set rst1 = New ADODB.Recordset
Set rst2 = New ADODB.Recordset
Set wbBook = ThisWorkbook
Set Sheet1 = wbBook.Worksheets(1)
'Path to the database.
stDB = "mysql32"
'Create the connectionstring.
strConn = "Driver=MySQL ODBC 5.2 Unicode Driver;" _
& "Data Source=" & stDB & ";"
'Sheet1.Activate
prBatchName = "tblProd_AGR_006"
totColumns = ActiveSheet.Cells(2, 1).CurrentRegion.Columns.count
totRows = ActiveSheet.Cells(2, 1).CurrentRegion.Rows.count
prBatchName = ActiveSheet.Cells(2, totColumns + 1).ID
cnt.Open strConn
rst2.Open "select * from " & prBatchName, cnt, adOpenStatic, adLockOptimistic
For j = 3 To totRows
WDS_id = ActiveSheet.Cells(j, 1)
rst2.Find "WDS_ID=" & WDS_id
For i = 2 To totColumns
rst2(ActiveSheet.Cells(2, i).ID) = ActiveSheet.Cells(j, i)
Next
rst2.Update
Next
rst2.Close
cnt.Close
MsgBox "Data updated sucessfully"