Private Sub ComUp_Click() '提交按钮 Dim strSQLChang As String Dim lngAffected As Long Dim textNum As Integer Dim textLeng As Integer Dim textNam As String Dim textTyp As String
Set cmdChange = New ADODB.Command Set cmdChange.ActiveConnection = gafcConnect
Dim strSQLChang As String
Dim lngAffected As Long
Dim textNum As Integer
Dim textLeng As Integer
Dim textNam As String
Dim textTyp As String
Set cmdChange = New ADODB.Command
Set cmdChange.ActiveConnection = gafcConnect
textNum = Num.Text
textNam = Nam.Text
textTyp = Typ.Text
textLeng = Leng.Text
strSQLChang = "UPDATE tab_msg_from SET Field_name ='" + Trim(textNum) _
+ "', Field_type=" + Trim(textTyp) + ",Field_length ='" + Trim(textLeng) _
+ "'WHERE Serial_Num=" + Trim(textNum)
cmdChange.CommandText = strSQLChang
cmdChange.CommandType = adCmdText
cmdChange.Execute
End Sub
sql语句中你的表和相应的字段是否匹配
用+可能会和数字运算发生混淆
+ "', Field_type=" + Trim(textTyp) + ",Field_length ='" + Trim(textLeng) _
+ "'WHERE Serial_Num='"& Trim(textNum) &"'"后面的WHERE语句加了符号
strSQLChang = "UPDATE tab_msg_from SET Field_name ='" + Trim(textNam) _
+ "', Field_type=" + Trim(textTyp) + ",Field_length ='" + Trim(textLeng) _
+ "'WHERE Serial_Num='" & Trim(TextNum) & "'"运行后还是出现同样的错误,先谢谢楼上的各位细心解答,大家再帮忙看看
strSQLChang = "UPDATE tab_msg_from SET Field_name ='" & Trim(textNam) & _
"', Field_type=" & Int(textTyp) & ",Field_length ='" & Trim(textLeng) & _
"' WHERE Serial_Num=" & Trim(TextNum) Field_name 是字符类型
Field_type 是整数类型
Field_length 是字符类型
Serial_Num 是整数类型如果你的数据表 tab_msg_from 没有错,而字段名和字段类型都和我上面说的一样
那上面的语句应该可以的
"'WHERE Serial_Num='"是一个字符串常量,VB不可能控制的
应该在where前面加空格的
cmdChange.CommandType = adCmdText
cmdChange.Execute'''cmdChange.Execute 后面没有执行语句吧,这样试试吧cmdChange.CommandText = strSQLChang
cmdChange.CommandType = adCmdText
cmdChange.Execute strSQLChang
结构 :Serial_Num 数字
Field_name 文本
Field_type 文本
Field_length数字
"', Field_type='" & Trim(textTyp) & "',Field_length ='" & Int(textLeng) & _
"' WHERE Serial_Num=" & Trim(TextNum)
你的textTyp是正确的变量吗?是不是"textType"?如果是对象最好用对象属性,如:
textType.Text
tab_msg_from 为access数据库表
结构 :Serial_Num 数字
Field_name 文本
Field_type 文本
Field_length数字
==============================================================================
知道了,你看下面的语句行吗?strSQLChang = "UPDATE tab_msg_from SET Field_name ='" & Trim(textNam) & _
"', Field_type='" & Trim(textTyp) & "',Field_length =" & Int(textLeng) & _
" WHERE Serial_Num=" & Int(TextNum)Field_length 是数字,所以不能用 ' 号
你看看可以吗?
& "',Field_type='" & Trim(textTyp) & "',Field_length =" & Val(textLeng) _
& " WHERE Serial_Num=" & Val(TextNum)
gafcConnect
'---gafcConnect.CursorLocation = adUseClient
cmdChange.Execute