用vb连接sql数据库时总是提示:ADODC:没有指定记录源[ADO]:没有为命令对象设置命令
PrivateSubForm_Load()'连接数据库Adodc1.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;...
Private Sub Form_Load()
'连接数据库
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\VB\ypxxdj.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from ypxxdj"
Adodc1.Refresh
End Sub
Private Sub cmdAdd_click()
On Error GoTo err1
With Adodc1
RecordSource = "select * from ypxxdj where YpNo ='" & txtYpNo.Text & "'"
Refresh
Recordset.AddNew
Recordset.Fields("YpNo") = txtYpNo.Text
Recordset.Fields("YpName") = txtYpName.Text
Recordset.Fields("UnitPrice") = CCur(txtUnitPrice.Text)
Recordset.Update
txtYpNo.Text = ""
txtYpName.Text = ""
txtUnitPrice.Text = ""
End With
Exit Sub
err1:
MsgBox "药品登记项目填写不完整或数据类型不匹配!"
End Sub
Private Sub cmdClose_click()
Unload Me
End Sub
Private Sub txtYpNo_change()
On Error GoTo err2
With Adodc1
RecordSource = "select * from ypxxdj where YpNo = '" & txtYpNo.Text & "'"
Refresh
If Recordset.AbsolutePosition <> adposunknow Then
If Recordset.Fields("YpNo") = txtYpNo.Text Then
txtYpNo.Text = Recordset.Fields("YpNo")
txtYpName.Text = Recordset.Fields("YpName")
txtUnitPrice.Text = Recordset.Fields("UnitPrice")
MsgBox "该药品编号已存在,你所选的编号可能重复!"
txtYpNo.Text = ""
txtYpName.Text = ""
txtUnitPrice.Text = ""
Else
txtYpName.Text = ""
txtUnitPrice.Text = ""
End If
End If
End With
Exit Sub
err2:
MsgBox "数据库出错或数据类型不匹配!"
End Sub 展开
'连接数据库
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\VB\ypxxdj.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from ypxxdj"
Adodc1.Refresh
End Sub
Private Sub cmdAdd_click()
On Error GoTo err1
With Adodc1
RecordSource = "select * from ypxxdj where YpNo ='" & txtYpNo.Text & "'"
Refresh
Recordset.AddNew
Recordset.Fields("YpNo") = txtYpNo.Text
Recordset.Fields("YpName") = txtYpName.Text
Recordset.Fields("UnitPrice") = CCur(txtUnitPrice.Text)
Recordset.Update
txtYpNo.Text = ""
txtYpName.Text = ""
txtUnitPrice.Text = ""
End With
Exit Sub
err1:
MsgBox "药品登记项目填写不完整或数据类型不匹配!"
End Sub
Private Sub cmdClose_click()
Unload Me
End Sub
Private Sub txtYpNo_change()
On Error GoTo err2
With Adodc1
RecordSource = "select * from ypxxdj where YpNo = '" & txtYpNo.Text & "'"
Refresh
If Recordset.AbsolutePosition <> adposunknow Then
If Recordset.Fields("YpNo") = txtYpNo.Text Then
txtYpNo.Text = Recordset.Fields("YpNo")
txtYpName.Text = Recordset.Fields("YpName")
txtUnitPrice.Text = Recordset.Fields("UnitPrice")
MsgBox "该药品编号已存在,你所选的编号可能重复!"
txtYpNo.Text = ""
txtYpName.Text = ""
txtUnitPrice.Text = ""
Else
txtYpName.Text = ""
txtUnitPrice.Text = ""
End If
End If
End With
Exit Sub
err2:
MsgBox "数据库出错或数据类型不匹配!"
End Sub 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询