vb插入数据库出了问题?怎样解决啊?弹出错误是“要求对像”,求高手赐教
下面是代码PrivateSubCommand1_Click()OnErroGoToerrIfTrim(Combo1.Text)=""ThenIfMsgBox("商品名称字...
下面是代码
Private Sub Command1_Click()
On Erro GoTo err
If Trim(Combo1.Text) = "" Then
If MsgBox("商品名称字段是必须要输入的!", vbExclamation, "提示!") = vbOK Then
Combo1.SetFocus
End If
Else
If Text8.Text = "" Then
If MsgBox("数量字段是必须要输入的!", vbExclamation, "提示") = vbOK Then
Text8.SetFocus
End If
Else
If Text6.Text = "" Then
If MsgBox("进价字段是必须输入的!", vbExclamation, "提示") Then
Text6.SetFocus
End If
Else
If Trim(Combo3.Text) = "" Then
If MsgBox("供应商字段是必须要输入的!", vbExclamation, "提示!") = vbOK Then
Combo3.SetFocus
End If
Else
If Trim(Combo2.Text) = "" Then
If MsgBox("经手人字段是必须要输入的!", vbExclamation, "提示") = vbOK Then
Combo2.SetFocus
End If
Else
connstring = "Provider=SQLOLEDB.1;Password=19901024123;Persist Security Info= True;User ID=sa; Initial Catalog=PurchaseandSale;Server=(local)"
If conn.State <> 1 Then
conn.Open (connstring)
End If
Dim sql As String
Dim sq As Adodc
sql = "insert into Purchase (商品名称,数量,进价,金额,备注,供应商,日期,经手人,票号)values( '" & Trim(Combo1.Text) & "'," & Trim(Text8.Text) & "," & Trim(Text6.Text) & "," & Trim(Text7.Text) & ",'" & Trim(Text9.Text) & "','" & Trim(Combo3.Text) & "','" & Trim(mebData.Text) & "','" & Trim(Combo2.Text) & "','" & Trim(Text3.Text) & "')"
conn.Execute (sql)
conn.Close
If MsgBox("采购单成功生成!", vbInformation, "提示") = vbOK Then
Unload frmCGD
End If
End If
End If
End If
End If
End If
err:
End Sub
按调试后
自动黄色选择了这条
sql = "insert into Purchase (商品名称,数量,进价,金额,备注,供应商,日期,经手人,票号)values( '" & Trim(Combo1.Text) & "'," & Trim(Text8.Text) & "," & Trim(Text6.Text) & "," & Trim(Text7.Text) & ",'" & Trim(Text9.Text) & "','" & Trim(Combo3.Text) & "','" & Trim(mebData.Text) & "','" & Trim(Combo2.Text) & "','" & Trim(Text3.Text) & "')"
图片 展开
Private Sub Command1_Click()
On Erro GoTo err
If Trim(Combo1.Text) = "" Then
If MsgBox("商品名称字段是必须要输入的!", vbExclamation, "提示!") = vbOK Then
Combo1.SetFocus
End If
Else
If Text8.Text = "" Then
If MsgBox("数量字段是必须要输入的!", vbExclamation, "提示") = vbOK Then
Text8.SetFocus
End If
Else
If Text6.Text = "" Then
If MsgBox("进价字段是必须输入的!", vbExclamation, "提示") Then
Text6.SetFocus
End If
Else
If Trim(Combo3.Text) = "" Then
If MsgBox("供应商字段是必须要输入的!", vbExclamation, "提示!") = vbOK Then
Combo3.SetFocus
End If
Else
If Trim(Combo2.Text) = "" Then
If MsgBox("经手人字段是必须要输入的!", vbExclamation, "提示") = vbOK Then
Combo2.SetFocus
End If
Else
connstring = "Provider=SQLOLEDB.1;Password=19901024123;Persist Security Info= True;User ID=sa; Initial Catalog=PurchaseandSale;Server=(local)"
If conn.State <> 1 Then
conn.Open (connstring)
End If
Dim sql As String
Dim sq As Adodc
sql = "insert into Purchase (商品名称,数量,进价,金额,备注,供应商,日期,经手人,票号)values( '" & Trim(Combo1.Text) & "'," & Trim(Text8.Text) & "," & Trim(Text6.Text) & "," & Trim(Text7.Text) & ",'" & Trim(Text9.Text) & "','" & Trim(Combo3.Text) & "','" & Trim(mebData.Text) & "','" & Trim(Combo2.Text) & "','" & Trim(Text3.Text) & "')"
conn.Execute (sql)
conn.Close
If MsgBox("采购单成功生成!", vbInformation, "提示") = vbOK Then
Unload frmCGD
End If
End If
End If
End If
End If
End If
err:
End Sub
按调试后
自动黄色选择了这条
sql = "insert into Purchase (商品名称,数量,进价,金额,备注,供应商,日期,经手人,票号)values( '" & Trim(Combo1.Text) & "'," & Trim(Text8.Text) & "," & Trim(Text6.Text) & "," & Trim(Text7.Text) & ",'" & Trim(Text9.Text) & "','" & Trim(Combo3.Text) & "','" & Trim(mebData.Text) & "','" & Trim(Combo2.Text) & "','" & Trim(Text3.Text) & "')"
图片 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询