在SQLServer中Insert和Update语句中可以对整形字段使用单引号,也可以执行成功,
但有一个地方需要注意:
Dim objCnn As New ADODB.Connection
Dim strSQL As String
On Error GoTo ErrHandle
strSQL = "Insert Into MyTest(A,B) Values('A','1')" & vbCrLf & _
"Insert Into MyTest(A,B) Values('B','1')" & vbCrLf & _
"Insert Into MyTest(A,B) Values('C','CCC')"
With objCnn
.ConnectionString = "Provider=SQLOLEDB;Data Source=192.168.18.205;Database=Test;Uid=sa;Pwd=kicpassword"
.Open
End With
objCnn.BeginTrans
objCnn.Execute strSQL
objCnn.CommitTrans
objCnn.Close
MsgBox "OK"
'说明MyTest表字段A为varchar类型,B为int类型,注意:B为整形不能插入字符
如上语句注意第三行的Insert语句'CCC'是不能赋值给字段B的,
程序的执行结果是没有报错,提示了"OK",实际上查询数据库时一条记录也没有插入