|
各位老师好,在尝试使用sql update语句时遇到了问题,不知道错哪里,请帮忙解惑,本人vba水平一般,如果有更简洁快速的方法,还望指教,感激不尽!主要过程:先获取mysql表结构,写入到表格SH中,用户通过窗体将需要修改的内容写入SH,而后再进行update操作,主要代码如下:
- conn.Open strConn
- R = SH.Cells(Rows.Count, 1).End(xlUp).Row
- L = SH.Cells(2, Columns.Count).End(xlToLeft).Column
- For i = 3 To R
- StrSQL0 = "SELECT ID FROM " & TableName & " WHERE ID=" & SH.Cells(i, 1).value
- StrSQL = "UPDATE " & TableName & " SET"
- StrSQL = StrSQL & SH.Cells(2, 2) & "='" & Now() & "'"
- For j = 3 To L
- StrSQL = StrSQL & "," & SH.Cells(2, j) & "='" & SH.Cells(i, j).value & "'"
- Next
- StrSQL = StrSQL & " WHERE ID=" & SH.Cells(i, 1).value
- conn.Execute StrSQL
- Next
复制代码
|
|