标题:怎么向数据库到不进去东西?账户只有8分了,全给了
只看楼主
VBnext
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-4-24
结帖率:80%
已结贴  问题点数:8 回复次数:5 
怎么向数据库到不进去东西?账户只有8分了,全给了
刚刚接触VB数据库,有许多东西不懂(账户只有8分了)
新编写的程序进行到rs.Open "select from Table1", conn, adOpenStatic, adLockReadOnly出现错误?
哪位高手帮忙解决一下。附件为读取文件和.mdb数据库
程序如下:
3.rar (10.77 KB)

Private Sub Command1_Click()
   Dim intFreeNumber As Integer
    Dim conn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim rsArray() As String, fdArray() As String
    Dim i As Long, j As Long
    Dim strTemp As String
    Dim strfile As String
   
    intFreeNumber = FreeFile()
    Open App.Path & "\aa.txt" For Binary As #intFreeNumber
    Do While Not EOF(intFreeNumber)
      strTemp = Input(intFreeNumber, #intFreeNumber)
      strfile = strfile & strTemp
    Loop
    Close #intFreeNumber
    Set conn = New ADODB.Connection
   
    conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Persist Security Info=False"
    conn.Open
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open "select from Table1", conn, adOpenStatic, adLockReadOnly

    rsArray = Split(strfile, vbCrLf)
    For i = 0 To UBound(rsArray) - 1
        fdArray = Split(rsArray(i), ",")
        For j = 0 To 1
            rs.AddNew
            rs(0).Value = Trim(fdArray(0))
            rs(1).Value = Trim(fdArray(1))
        Next j
    Next i
    rs.UpdateBatch
    Set rs = Nothing
    Set conn = Nothing
End Sub
搜索更多相关主题的帖子: 数据库程序 
2013-07-05 17:16
LK868
Rank: 2
等 级:论坛游民
威 望:1
帖 子:25
专家分:96
注 册:2010-3-27
得分:8 
rs.Open "select * from [Table1]", conn, adOpenStatic, adLockOptimistic
2013-07-05 17:49
VBnext
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-4-24
得分:0 
回复 2楼 LK868
还是不行,不知道什么问题?
2013-07-07 11:18
LK868
Rank: 2
等 级:论坛游民
威 望:1
帖 子:25
专家分:96
注 册:2010-3-27
得分:0 
2个地方有问题:
rs.Open "select * from [Table1]", conn, adOpenStatic, adLockOptimistic
发现你的“aa.txt”文本里边最后有两行空值,所以rs(0).Value = Trim(fdArray(0))这里下标出错。
2013-07-07 15:57
VBnext
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-4-24
得分:0 
回复 4楼 LK868
给你你说的改了还是运行不了
运行到rs.Open "select from [Table1]", conn, adOpenStatic, adLockReadOnly还是提示错误如下:

2013-07-07 17:43
LK868
Rank: 2
等 级:论坛游民
威 望:1
帖 子:25
专家分:96
注 册:2010-3-27
得分:0 
不是:rs.Open "select from [Table1]", conn, adOpenStatic, adLockReadOnly
是:rs.Open "select * from [Table1]", conn, adOpenStatic, adLockOptimistic
2013-07-07 18:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-416737-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.057430 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved