VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > vb >
  • excel vba教程之SQL中用字符串变量和数值型变量

1.  SQL中用字符串变量和数值型变量

'sql中包含并使用变量str  (注意该变量是字符串)
Private Sub CommandButton7_Click()
Dim str As String
str = "my5"
Set conn = New ADODB.Connection: conn.Open "dsn=excel files;dbq=" & ThisWorkbook.Path & "\db.xls"
sql = "select * from [a$] where xm='" & str & "'"
[a2].CopyFromRecordset conn.Execute(sql): conn.Close: Set conn = Nothing
End Sub
'sql中包含并使用变量nl2  (注意该变量是数值型)
Private Sub CommandButton8_Click()
nl2 = 10
Set conn = New ADODB.Connection: conn.Open "dsn=excel files;dbq=" & ThisWorkbook.Path & "\db.xls"
sql = "select * from [a$] where nl= " & nl2 & ""
[a2].CopyFromRecordset conn.Execute(sql): conn.Close: Set conn = Nothing
 
End Sub

相关教程