Private Sub cmdPersonAdd_Click()
Dim rcset As Recordset
'adoData是一个Adodc控
'件,ado.ConnectionString= "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=" & dataPath
' & "data.mdb;Persist Security Info=False"adoData.CommandType = adCmdTable
adoData.RecordSource = "借阅人信息表"
adoData.RefreshIf txtPersonName.Text = "" Or txtDepartment.Text = "" Then
MsgBox "请完整添入所有信息!"
Exit Sub
End IfSet rcset = adoData.RecordsetOn Error GoTo errHandle '更新数据出现错误转到错误处理语句'添加一个新记录
rcset.AddNewrcset!证号 = txtPersonID.Text
rcset!姓名 = txtPersonName.Text
rcset!类别 = cboPersonClass.Text
rcset!部门 = txtDepartment.Textrcset.UpdateadoData.RefreshfrmMain.adoData.RefreshtxtPersonID.Text = AutoPersonID(adoData, "借阅人信息表", cboPersonClass.Text)
txtPersonName.Text = ""rcset.Close
Set rcset = Nothing
Exit SuberrHandle:
MsgBox "添加记录错误,请确认数据的正确性!"End Sub执行代码后出现,错误提示: [ADODC]:没有指定记录源 [ADO]:没有为命令对象设置命令
随后转到错误处理部分 提示:添加记录错误,请确认数据的正确性!
可是打开数据库后记录已经被添加了
Dim rcset As Recordset
'adoData是一个Adodc控
'件,ado.ConnectionString= "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=" & dataPath
' & "data.mdb;Persist Security Info=False"adoData.CommandType = adCmdTable
adoData.RecordSource = "借阅人信息表"
adoData.RefreshIf txtPersonName.Text = "" Or txtDepartment.Text = "" Then
MsgBox "请完整添入所有信息!"
Exit Sub
End IfSet rcset = adoData.RecordsetOn Error GoTo errHandle '更新数据出现错误转到错误处理语句'添加一个新记录
rcset.AddNewrcset!证号 = txtPersonID.Text
rcset!姓名 = txtPersonName.Text
rcset!类别 = cboPersonClass.Text
rcset!部门 = txtDepartment.Textrcset.UpdateadoData.RefreshfrmMain.adoData.RefreshtxtPersonID.Text = AutoPersonID(adoData, "借阅人信息表", cboPersonClass.Text)
txtPersonName.Text = ""rcset.Close
Set rcset = Nothing
Exit SuberrHandle:
MsgBox "添加记录错误,请确认数据的正确性!"End Sub执行代码后出现,错误提示: [ADODC]:没有指定记录源 [ADO]:没有为命令对象设置命令
随后转到错误处理部分 提示:添加记录错误,请确认数据的正确性!
可是打开数据库后记录已经被添加了
解决方案 »
- 当鼠标移动到窗体上的文字上时,鼠标箭头变成小手,文字下有下划线
- WebBrows 控件 调用 一个HTML页面,如果屏蔽 HTML 里的 onunload=window.open
- 提一个很基础的问题,怎样才能让字符串包含双引号?
- 报表表头问题,各位请进?
- 谁能用VB代码把这个网页的内容全部读出?谢谢
- 各位快帮我看看,这个API函数的使用是不是参数错了?RegQueryValueEx(hKey, keyvalue, 0&, REG_SZ, ByVal vbNullString, SizeOfData) , RegOpenKeyEx可得0!
- 有没有用过internet transfer control 6.0的?
- 有关使用input时按cancel时的一个问题!
- 我想找关于串行通讯技术方面的文章,谁能告诉我上那去找?
- 寻找Sql7.0的SP3的安装密码,也就是安装时要求录入的字符串
- 打印问题!kkkkkkkkkkkkkk
- 关于自定义坐标系问题
Dim rcset As RecordsetadoData.CommandType = adCmdTable
adoData.RecordSource = "图书表"
adoData.RefreshIf txtBookName.Text = "" Or txtAuthor.Text = "" Or cboPress.Text = "" Or txtTime.Text = "" Or cboBookClass.Text = "" Then
MsgBox "请完整填入所有信息!"
Exit Sub
End IfIf Not (txtTime.Text Like "*年*月") Then
MsgBox "出版时间格式错误(X年X月)!"
Exit Sub
End IfSet rcset = adoData.RecordsetOn Error GoTo errHandle '更新数据出现错误转到错误处理语句'添加一个新记录
rcset.AddNewrcset!书号 = txtBookID.Text
rcset!书名 = txtBookName.Text
rcset!作者 = txtAuthor.Text
rcset!出版社 = cboPress.Text
rcset!出版时间 = txtTime.Text
rcset!类别 = cboBookClass.Text
rcset.UpdateadoData.RefreshfrmMain.dgrdMain.RefreshtxtBookID.Text = AutoBookID(adoData, "图书表")
txtBookName.Text = ""
txtAuthor.Text = ""
txtTime.Text = ""rcset.Close
Set rcset = Nothing
Exit SuberrHandle:
MsgBox "添加记录错误,请确认数据的正确性!"
End Sub
txtPersonID.Text = AutoPersonID(adoData, "借阅人信息表", cboPersonClass.Text)frmMain.dgrdMain.Refresh
txtPersonID.Text = AutoBookID(adoData, "图书表")这两段大不同,是引用的对象错了吗?
我有DataGrid显示数据,显示的结果没有排序,可我明明在ACCESS里设置有主键索引排序
改为:
adoData.RecordSource = "图书表 order by 某字段"
Private Sub cmdPersonAdd_Click()
' Dim rcset As Recordset
'//这句话去掉,不用定义recordset了,adodc控件自身有recordset
'//adoData是一个Adodc控件, 下面这句话存在,指定数据源
ado.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=" & dataPath & "data.mdb;Persist Security Info=False" '//adoData.CommandType = adCmdTable '改为unknown状态等待自动识别,以防止发生错误,在vb当中错误会被忽略,但是在vb.net中则会产生错误机制
adoData.CommandType = adCmdUnknown
'//adoData.RecordSource = "借阅人信息表"
'//把借阅人的表名改成英文的,程序设计中用中文是大忌
'//用sql的查询语句去查询.而不是当存储过程去直接exec,你可以去试着了解adodc的工作原理就会明白
adoData.RecordSource = "Select * from People"
adoData.Refresh If txtPersonName.Text = "" Or txtDepartment.Text = "" Then
MsgBox "请完整添入所有信息!"
Exit Sub
End If 'Set rcset = adoData.Recordset 不用指定 On Error GoTo errHandle '更新数据出现错误转到错误处理语句
'//错误处理最好放在最前面,在对数据库的操作用resume next 过掉错误比较平常
'//也可以采用事务处理
'添加一个新记录
'rcset.AddNew
'rcset!证号 = txtPersonID.Text
'rcset!姓名 = txtPersonName.Text
'rcset!类别 = cboPersonClass.Text
'rcset!部门 = txtDepartment.Text
' rcset.Update
'adoData.Refresh
' frmMain.adoData.Refresh
'//建议把数据库中间的字段全部换成英文
'//直接用adodc自身的recordset就可操作,用recordset,且没定义new recordset如何不错
'//原来代码简直是画蛇添足
adoData.Recordset.AddNew
adoData.Recordset("ID") = txtPersonID.Text
adoData.Recordset("PersonName") = txtPersonName.Text
adoData.Recordset("PersonClass") = cboPersonClass.Text
adoData.Recordset("Department") = txtDepartment.Text
adoData.Recordset.Update
'/仔细检查 AutoPersonID这个function,禁止掉中文名称,对有text的变量一律需要用Trim过滤空格,防止发生错误
txtPersonID.Text = AutoPersonID(adoData, "借阅人信息表", cboPersonClass.Text)
txtPersonName.Text = "" 'rcset.Close
'Set rcset = Nothing
'//整个adodc1的recordset最好不到最后就不要关闭,最后再从内存销掉
'//一般一个recordset对象最好是全局使用
Exit SuberrHandle:
MsgBox "添加记录错误,请确认数据的正确性!"End Sub
你数据库连接没有写引行