vba excel mysql Καλημέρα παιδιά
πειραματίζομαι με excel vba και σύνδεση MySQL. Παραθέτω τον παρακάτω κώδικα Κώδικας:
Private Sub CommandButton2_Click()
Dim con As ADODB.Connection
Dim rst As ADODB.Recordset
Set con = New ADODB.Connection
con.Open "DRIVER={Mysql ODBC 8.0 Unicode Driver};" _
& "Server=localhost;database=loginapp;user=root;option=3"
Dim sqlstr As String
Dim crow As Long, trow As Long
Dim id As Integer
Dim username As String
Dim password As String
Set rst = New ADODB.Recordset
trow = Sheets("Service Company 1").Range("b" & Rows.Count).End(xlUp).Row
For crow = 7 To trow
id = Sheets("service company 1").Range("b" & crow).Value
username = Sheets("service company 1").Range("c" & crow).Value
password = Sheets("service company 1").Range("d" & crow).Value
'sqlstr = "INSERT INTO USERS (id, username, password) values ( ' " & id & " ', " & " ' " & username & "', " & " ' " & password & "')"
sqlstr = "INSERT INTO USERS (username, password) values ( ' " & username & "', " & " ' " & password & "')"
rst.Open sqlstr, con, adOpenForwardOnly
Next
Set rst = Nothing
con.Close
Set con = Nothing
MsgBox ("Data inserted, succedssfully")
End Sub Το θέμα μου είναι, πως μπορώ να ελέγξω σε πια κελιά υπάρχουν δεδομένα στο excel, γιατί με αυτόν τον τρόπο μου ανεβάζει στην database και τα κελιά που δεν έχουν δεδομένα.
Δεν ξέρω εάν το έχω εξηγήσει αναλυτικά
Ευχαριστώ |