我想在select 语句中使用一个变量,不知道怎么用啊例如,select * from company where id=i
其中,i是一个变量,不是固定值
其中,i是一个变量,不是固定值
解决方案 »
- 小妹不才,问个基础问题VARIANT是什么类型怎么用啊?
- 如何根据模板新建一个WORD文件,并替换指定的字符
- vb.net在第一步骤就不能安装,iis我装了,请求各位高手指教下,小弟不盛感激
- 使用Data控件出现错误:实时错误3170 找不到可插入的ISAM。怎么办?
- 请问如何把本地文件用ado.steam写入数据库
- 运行 activerepot 2 的示例代码 后退出vb6时发生错误,"发送报告..." 求教是什么原因?
- 如何获得文件的创建时间!!!!!!
- 哪位高手能帮忙分析一下内存增长问题!
- 急:如何判断设计模式与运行模式的状态,
- 请问:考那种证比较好找到程序员的工作?
- VB没有窗体
- 如何获得桌面上具体图标的句柄
本范例在已打开的 Recordset 和 Connection 对象上使用 Open 和 Close 方法。'BeginOpenVB 'To integrate this code
'replace the data source and initial catalog values
'in the connection stringPublic Sub OpenX()
On Error GoTo ErrorHandler Dim Cnxn As ADODB.Connection
Dim rstEmployees As ADODB.Recordset
Dim strCnxn As String
Dim strSQLEmployees As String
Dim varDate As Variant
' Open connection
strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _
"Initial Catalog='Pubs';Integrated Security='SSPI';"
Set Cnxn = New ADODB.Connection
Cnxn.Open strCnxn
' Open employee table
Set rstEmployees = New ADODB.Recordset
strSQLEmployees = "employee"
rstEmployees.Open strSQLEmployees, Cnxn, adOpenKeyset, adLockOptimistic, adCmdTable
' Assign the first employee record's hire date
' to a variable, then change the hire date
varDate = rstEmployees!hire_date
Debug.Print "Original data"
Debug.Print " Name - Hire Date"
Debug.Print " " & rstEmployees!fname & " " & _
rstEmployees!lname & " - " & rstEmployees!hire_date
rstEmployees!hire_date = #1/1/1900#
rstEmployees.Update
Debug.Print "Changed data"
Debug.Print " Name - Hire Date"
Debug.Print " " & rstEmployees!fname & " " & _
rstEmployees!lname & " - " & rstEmployees!hire_date
' Requery Recordset and reset the hire date
rstEmployees.Requery
rstEmployees!hire_date = varDate
rstEmployees.Update
Debug.Print "Data after reset"
Debug.Print " Name - Hire Date"
Debug.Print " " & rstEmployees!fname & " " & _
rstEmployees!lname & " - " & rstEmployees!hire_date ' clean up
rstEmployees.Close
Cnxn.Close
Set rstEmployees = Nothing
Set Cnxn = Nothing
Exit Sub
ErrorHandler:
' clean up
If Not rstEmployees Is Nothing Then
If rstEmployees.State = adStateOpen Then rstEmployees.Close
End If
Set rstEmployees = Nothing
If Not Cnxn Is Nothing Then
If Cnxn.State = adStateOpen Then Cnxn.Close
End If
Set Cnxn = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
'EndOpenVB
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
sql="select * from company where id=" & i