大家帮我看看,大家帮我看看这个程序,谢谢了!20

大家帮我看看这个程序,谢谢了!20 - 故障解答 - 电脑教程网

大家帮我看看这个程序,谢谢了!20

日期:2007-02-12   荐:
大家帮我看看这个程序,谢谢了!20用ADO语句连接了一个ACCESS,能够在TEXT中正常显示,现在希望点一个按钮,遍历这个数据库下面这段是连接数据库并显示Private Sub Form_Load()cn.Provider = "microsoft.jet.oledb.4.0"cn.ConnectionString = "data source=E:\毕业设计\VB Program\serve\hc.mdb"cn.Openrs.LockType = adLockOptimisticrs.CursorType = adOpenKeysetSet rs.ActiveConnection = cnrs.Open "select * from b1"Set .DataSource = rs.DataField = "ID"Set .DataSource = rs.DataField = "date"Set Text3.DataSource = rsText3.DataField = "time"Set Text4.DataSource = rsText4.DataField = "sv"Set Text5.DataSource = rsText5.DataField = "pv"Set Text6.DataSource = rsText6.DataField = "al"If Text6.Text = "1" ThenText6.Text = "是"ElseText6.Text = "否"End IfEnd Sub这是我写的遍历方法,点完按钮后总是显示错误,能告诉我是错在了哪里了么?谢谢Private Sub Command4_Click()If Not rs.EOF Thenrs.MoveNextElse: rs.MoveLastEnd IfEndEnd Sub你变量申明在哪了?如果你没有申明过的话,那肯定出错,因为rs在load后就释放了变量在最前面已经声明好了,没贴出来Option ExplicitDim cn As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim cm As New ADODB.Command我是想知道,那个遍历小程序错误出在哪里,谢谢else 后面没冒号,发错了,大家帮我看看啊晕,else 后面加冒号啊,我说怎么没错呢。要不Private Sub Command4_Click()If Not rs.EOF Thenrs.MoveNextElsers.MoveLastEnd IfEnd'''''好象多了,删除了End Sub要不else 后另起一行Option ExplicitDim cn As New adodb.ConnectionDim rs As New adodb.RecordsetDim cm As New adodb.CommandPrivate Sub Form_Load()cn.Provider = "microsoft.jet.oledb.4.0"cn.ConnectionString = "data source=E:\毕业设计\VB Program\serve\hc.mdb"cn.Openrs.LockType = adLockOptimisticrs.CursorType = adOpenKeysetSet rs.ActiveConnection = cnrs.Open "select * from b1"Set .DataSource = rs.DataField = "ID"Set .DataSource = rs.DataField = "date"Set Text3.DataSource = rsText3.DataField = "time"Set Text4.DataSource = rsText4.DataField = "sv"Set Text5.DataSource = rsText5.DataField = "pv"Set Text6.DataSource = rsText6.DataField = "al"If Text6.Text = "1" ThenText6.Text = "是"ElseText6.Text = "否"End IfEnd SubPrivate Sub Command4_Click()If Not rs.EOF Thenrs.MoveNextElsers.MovePreviousEnd IfEnd Sub整个程序改成上面的仍然不能正确执行啊不能正确执行,提示出错的地方在哪?只说是实时错误‘-2147217842(80040e4e)'报错报的什么?调试指向哪行呢?Private Sub Command4_Click()指向这里数据库没连上用户名和密码有吗?一步步来先看看连接数据库有没有问题可以先加一个datagrid控件,然后set datagrid.datasource=rs看看能不能显示到datagrid看了下好像还少了这么一句 ' 使用客户端数据游标 cn.CursorLocation = adUseClient少了这句不会出现楼主显示的这个问题应该还有其它错'工程->引用->Microsoft ActiveX Data Objects 2.X Library'莫依MM原创Option ExplicitPrivate Rs As New ADODB.RecordsetPrivate Conn As New ADODB.ConnectionPrivate Sub Form_Load() Dim strConn As String ' 连接数据库的字符串 ' 连接带密码的数据库,直接在连接符后面加上Jet OLEDB:DataBase Password='您的密码' ' 连接Access97数据库需要使用Jet.OLEDB.3.5,Access2K和以上数据库使用Jet.OLEDB.4.0 strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Persist Security Info=False" ' 使用客户端数据游标 Conn.CursorLocation = adUseClient ' 打开Access的连接 Conn.Open strConn ' 如果RecordSet的状态不是关闭状态,则关闭Recordset If Rs.State <> adStateClosed Then Rs.Close ' Recordser打开表People Rs.Open "Select * from People", Conn, adOpenKeyset, adLockOptimistic ' 报告出 一共多少笔数据,测试是否存在数据 ' MsgBox Rs.RecordCount ' 绑定进DataGrid Set DataGrid1.DataSource = Rs End Sub数据库要是没连上的话应该不能正确显示啊,现在可以正确的显示,就是不能点“下一个”按钮进行遍历?gt;>C挥杏没
标签: