测试VBA是否与SQL连接?以及将TExtbox数据存入sql表中?
Dim CN As New ADODB.Connection
Dim rs As ADODB.recordset
Dim sql As String
Set CN = New ADODB.Connection
CN.Open "Provider=SQLOLEDB;user ID=sa;Password=***;Date Sourse=(127.0.0.1);Datebase=smh"
sql = "insert into smh(T) values( textbox1.text )"
Set rs = Nothing
Set CN = Nothing
[解决办法]
Private Sub ado_proc()
Dim conn As ADODB.Connection
Dim sSql As String
Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB;user ID=sa;Password=***;Date Sourse=(127.0.0.1);Datebase=smh"
If conn.State = adStateOpen Then
'到此部说明数据库已连接
sSql = "insert into smh(T) values( textbox1.text )"
'
conn.Close
End If
Set conn = Nothing
End Sub