vba using the UPDATE operation Mysql groups of data update

After determining line syntax examples found in Comprehensive Update:
the UPDATE MyTable the CASE = MyField the WHEN the SET. 1 THEN 'value' the WHEN 2 THEN 'value'. 3 the WHEN THEN 'value' the END the WHERE ID the IN (l, 2,3)

Here is what I wrote a generic update the database table contents process: kku as a library table, zd for the field, frow to update the values in the table the first few empty row, col column where the value is updated, ygs for the number of employees.
NOTE: Update written characters and numbers are different, and therefore were judged by IsNumeric (Cells (1 + frow, col)).
Function: can be a data table, a writing table field. Writing the value of a controlled amount of the generic process.

WRITEB Sub (KKU of As String, String ZD of As, FROW of As Integer, Integer COL of As, YGS of As Integer)
PSW = "123456"
ku = "kp123"
User = "user123"
IP = "127.0.0.1"
Dim New Cnn of As the ADODB .Connection
Dim RS of As New ADODB.Recordset
Dim A of As String
A = "{the MySQL the DRIVER = 5.3 the Unicode the ODBC Driver}; SERVER =" IP & & "; Database =" & & ku "; Uid =" User & & "; = pwd "PSW & &"; Stmt = GB2312 names SET "
the Set Cnn = the CreateObject (" ADODB.Connection "



rs.CursorType = adOpenStatic 'the cursor type, or can not get the row
rs.CursorLocation = adUseClient' cursor attributes set, otherwise it is impossible to obtain the number of rows
rr = "(1" 'rr deposited with id range, with the condition stored qq and assigned to the first and qq rr forming an initial value (i.e. a value of 1 when id)
the If the IsNumeric (Cells (+ FROW. 1, COL)) the Then
qq = "when the then. 1 id =" & Cells (+ FROW. 1, col) 'is updated digital
Else
QQ = "ID = When the then. 1'" & Cells (+ FROW. 1, COL) & " '"' string is updated, the single quotation marks around must
End the If
the for I = 2 the to YGS
RR = RR & "," & I
the If the IsNumeric (Cells (I + FROW, COL)) the Then
QQ = QQ + "When ID =" & I & "the then" & Cells (I + FROW, COL)
Else
QQ = qq + "when id =" & i & "then '" & Cells (i + frow,col) & "'"
End If
Next
rr = rr & ")"
rs.Open "update " & kku & " set " & zd & " = case " & qq & " end where id in " & rr & ";", Cnn, 3, 1
Cnn.Close
Set Cnn = Nothing
End Sub

Guess you like

Origin www.cnblogs.com/tywusy/p/12129312.html