it shows update succesfully but it is not update in the database please let me know

ubaig

New Member
Joined
Mar 18, 2014
Messages
17
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

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"
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,223,277
Messages
6,171,148
Members
452,382
Latest member
RonChand

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top