用VB连接SQL server 2005实现对数据库的增删改查,我照书上写的语句,全是错误,我菜鸟啊~~求大神帮帮~
PrivateSubCommand1_Click()DimintCountAsIntegerDimsMegAsStringDimmrcAsADODB.RecordsetD...
Private Sub Command1_Click()
Dim intCount As Integer
Dim sMeg As String
Dim mrc As ADODB.Recordset
Dim MsgText As String
'判断输入内容是否为空
For intCount = 0 To 4
If Trim(Text1(intCount) & "") = "" Then
Select Case intCount
Case 0
sMeg = "出库编号"
Case 1
sMeg = "商品名称"
Case 2
sMeg = "数量"
Case 3
sMeg = "出库时间"
Case 4
sMeg = "经办人"
End Select
sMeg = sMeg & "不能为空!"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Text1(intCount).SetFocus
Exit Sub
End If
Next intCount
'判断是否有相同的ID记录
If gintMmode = 1 Then
'组成查询语句
txtSQL = "selcet * from 出库信息表 where ckno ='" & Trim(Text1(0)) & "'"
Set mrc = executeSQL(txtSQL, MsgText)
'判断是否有重复记录
If mrc.EOF = False Then
MsgBox "已经存在此商品编号的记录!", vbOKOnly + vbExclamation, "警告"
'获得输入焦点
Text1(0).SetFocus
Exit Sub
End If
'关闭数据集对象
mrc.Close
End If
'判断是否有相同内容的记录
txtSQL = "select * from 出库信息表 where rkno <>'" & Trim(Text1(0)) & "'and rkname='" & Trim(Text1(1)) & "'and rkaccount='" & Trim(Text1(2)) & "'"
Set mrc = executeSQL(txtSQL, MsgText)
'判断数据集对象是否为空
If Not mrc.EOF Then '存在相同记录'
MsgBox "已经存在相同商品内容的记录!", vbOKOnly + vbExclamation, "警告"
Text1(1).SetFocus
Exit Sub
End If
'先删除已有的记录
txtSQL = "delete from 出库信息表 where rkno='" & Trim(Text1(0)) & "'"
Set mrc = executeSQL(txtSQL, MsgText)
'再加入新纪录
txtSQL = "select * from 出库信息表"
Set mrc = executeSQL(txtSQL, MsgText)
'在数据集对象中添加记录
mrc.AddNew
'赋值
mrc.Fields(0) = Trim(Text1(intCount))
For intCount = 1 To 4
mrc.Fields(intCount) = Trim(Text1(intCount))
Next intCount
'添加数据到数据库
mrc.Update
'关闭数据集对象
mrc.Close
'判断是否为添加状态
If gintMmode = 1 Then
MsgBox "添加记录成功!", vbOKOnly + vbExclamation, "添加记录"
'清空文本框内容
For intCount = 0 To 4
Text1(intCount) = ""
Next intCount
'修改标志
mblChange = False
'更新记录内容
If flagMedit Then
'卸载窗体
Unload Form3
'获得所有记录
Form3.Show
End If
'判断是否处于修改状态
ElseIf gintMmode = 2 Then
'卸载窗体
Unload Me
If flagMedit Then
Unload Form3
End If
'更新记录内容
Form3.txtSQL = "select * from 出库信息表"
Form3.Show
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim txtSQL As String
Dim MsgText As String
Dim gintMmode As Boolean
Dim mblChange As Boolean
'记录确定次数
Dim miCount As Integer
Dim MsgTxet As String
Dim mrc As ADODB.Recordset
Dim intCount As Integer
End Sub 展开
Dim intCount As Integer
Dim sMeg As String
Dim mrc As ADODB.Recordset
Dim MsgText As String
'判断输入内容是否为空
For intCount = 0 To 4
If Trim(Text1(intCount) & "") = "" Then
Select Case intCount
Case 0
sMeg = "出库编号"
Case 1
sMeg = "商品名称"
Case 2
sMeg = "数量"
Case 3
sMeg = "出库时间"
Case 4
sMeg = "经办人"
End Select
sMeg = sMeg & "不能为空!"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Text1(intCount).SetFocus
Exit Sub
End If
Next intCount
'判断是否有相同的ID记录
If gintMmode = 1 Then
'组成查询语句
txtSQL = "selcet * from 出库信息表 where ckno ='" & Trim(Text1(0)) & "'"
Set mrc = executeSQL(txtSQL, MsgText)
'判断是否有重复记录
If mrc.EOF = False Then
MsgBox "已经存在此商品编号的记录!", vbOKOnly + vbExclamation, "警告"
'获得输入焦点
Text1(0).SetFocus
Exit Sub
End If
'关闭数据集对象
mrc.Close
End If
'判断是否有相同内容的记录
txtSQL = "select * from 出库信息表 where rkno <>'" & Trim(Text1(0)) & "'and rkname='" & Trim(Text1(1)) & "'and rkaccount='" & Trim(Text1(2)) & "'"
Set mrc = executeSQL(txtSQL, MsgText)
'判断数据集对象是否为空
If Not mrc.EOF Then '存在相同记录'
MsgBox "已经存在相同商品内容的记录!", vbOKOnly + vbExclamation, "警告"
Text1(1).SetFocus
Exit Sub
End If
'先删除已有的记录
txtSQL = "delete from 出库信息表 where rkno='" & Trim(Text1(0)) & "'"
Set mrc = executeSQL(txtSQL, MsgText)
'再加入新纪录
txtSQL = "select * from 出库信息表"
Set mrc = executeSQL(txtSQL, MsgText)
'在数据集对象中添加记录
mrc.AddNew
'赋值
mrc.Fields(0) = Trim(Text1(intCount))
For intCount = 1 To 4
mrc.Fields(intCount) = Trim(Text1(intCount))
Next intCount
'添加数据到数据库
mrc.Update
'关闭数据集对象
mrc.Close
'判断是否为添加状态
If gintMmode = 1 Then
MsgBox "添加记录成功!", vbOKOnly + vbExclamation, "添加记录"
'清空文本框内容
For intCount = 0 To 4
Text1(intCount) = ""
Next intCount
'修改标志
mblChange = False
'更新记录内容
If flagMedit Then
'卸载窗体
Unload Form3
'获得所有记录
Form3.Show
End If
'判断是否处于修改状态
ElseIf gintMmode = 2 Then
'卸载窗体
Unload Me
If flagMedit Then
Unload Form3
End If
'更新记录内容
Form3.txtSQL = "select * from 出库信息表"
Form3.Show
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim txtSQL As String
Dim MsgText As String
Dim gintMmode As Boolean
Dim mblChange As Boolean
'记录确定次数
Dim miCount As Integer
Dim MsgTxet As String
Dim mrc As ADODB.Recordset
Dim intCount As Integer
End Sub 展开
2个回答
展开全部
照书上写的语句,全是错误,主要是语法错误,你注意一下,就可以了。例如:
'判断是否有相同内容的记录
txtSQL = "select * from 出库信息表 where rkno <>'" & Trim(Text1(0)) & "'and rkname='" & Trim(Text1(1)) & "'and rkaccount='" & Trim(Text1(2)) & "'"
Set mrc = executeSQL(txtSQL, MsgText)
应该改为:
'判断是否有相同内容的记录
txtSQL = "select * from 出库信息表 where rkno <>'"" & Trim(Text1(0)) & ""'and rkname='"" & Trim(Text1(1)) & ""'and rkaccount="'" & Trim(Text1(2)) & "'"
Set mrc = executeSQL(txtSQL, MsgText)
这些错误,就是印刷时候的错误,或者是你输入时候的错误,你得认真看准了。
"" 是错的,应该是 """ .
'判断是否有相同内容的记录
txtSQL = "select * from 出库信息表 where rkno <>'" & Trim(Text1(0)) & "'and rkname='" & Trim(Text1(1)) & "'and rkaccount='" & Trim(Text1(2)) & "'"
Set mrc = executeSQL(txtSQL, MsgText)
应该改为:
'判断是否有相同内容的记录
txtSQL = "select * from 出库信息表 where rkno <>'"" & Trim(Text1(0)) & ""'and rkname='"" & Trim(Text1(1)) & ""'and rkaccount="'" & Trim(Text1(2)) & "'"
Set mrc = executeSQL(txtSQL, MsgText)
这些错误,就是印刷时候的错误,或者是你输入时候的错误,你得认真看准了。
"" 是错的,应该是 """ .
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询