1. 把打开连接的程序改成如下的方式试试:
cn.provider="Microsoft.Jet.OLEDB.4.0"
cn.open "c:\student.mdb"2. 如果字段是字符型的,要加上单引号
sql = "insert into std(字段1,字段2) " & _
"values ('" & text1.text & "','" & text2.text & "')"
cn.provider="Microsoft.Jet.OLEDB.4.0"
cn.open "c:\student.mdb"2. 如果字段是字符型的,要加上单引号
sql = "insert into std(字段1,字段2) " & _
"values ('" & text1.text & "','" & text2.text & "')"
Dim rs As New ADODB.Recordset
cn.Open "dsn=std", "Admin", ""
If cn.State = adStateOpen Then
MsgBox "ok"
Else
MsgBox "no"
End If
sql = "insert into std values(" & Text1.Text & "," & Text2.Text & ")"
cn.Execute sql
这样应该好了
sub adoconnect3(ByVal MyDatabase As String, ByVal MyTable As String)
Dim MyRs As ADODB.Recordset
Dim MyConnectString As String
Dim sql As String
' 打开连接。
MyPath = getapppathparent + "database\"
MyConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & MyPath & MyDatabase & ";Jet OLEDB:Database Password=" & DataBasePassword '其中(DataBasePassword )为数据库的密码
Set MyCnn = New ADODB.Connection
MyCnn.Open MyConnectString
'执行Sql语句
Set MyRs = New ADODB.Recordset
sql = "insert into " & MyTable & "values(" & Text1.Text & "," & Text2.Text & ")"
MyCnn.Execute sql
End sub将其中的Sql语句变一下就行了
2、别外将你的SQL 语句改为:
sql = "insert into std(field1,field2) values('" & Text1.Text & "','" & Text2.Text & "')"
改成cn.ConnectionString = "Driver={Microsoft Access 2000};dsn=student;uid=Admin;pwd="
为什么我只能设为 Microsoft.Jet.OLEDB.3.51 的.一设为 4.0
就会提示出错.
就会提示出错.
这是因为你没有安装最新的ado驱动,安装一下就行了。
Insert Into students
Values (11,"影子","男","1999-12-12","湖北","83779805","武汉市桥口区","VB爱好者")
你的语句
sql = "insert into std values(" & Text1.Text & "," & Text2.Text & ")"没有
改成如下的试试
QuotationMarks = """" '代表双引号
TempStr1=QuotationMarks & Text1.Text & QuotationMarks
TempStr2=QuotationMarks & Text2.Text & QuotationMarks
sql = "insert into std values(" & TempStr1 & "," & TempStr2 & ")"