| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 829 人关注过本帖
标题:ACCESS数据库导入的数据不能使用
取消只看楼主 加入收藏
yang3396789
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-4-23
收藏
 问题点数:0 回复次数:0 
ACCESS数据库导入的数据不能使用
从EXCEL导入到ACCESS中的数据,在程序中点开就报错,运行时错误‘94’使用Null无效
但是表里面的值都是有的啊。求各位大神帮忙解决一下!真心的不懂。是在哪个地方判断数据是空值的?
Option Explicit
Dim Flag As Integer
Private Sub ShowRecord()
Dim i As Integer, j As Integer
Adodc2.Refresh
With MSHFlexGrid1
    .Rows = 1
    If Adodc2.Recordset.RecordCount > 0 Then Adodc2.Recordset.MoveFirst
    For i = 1 To Adodc2.Recordset.RecordCount
        If i + 1 > .Rows Then .Rows = .Rows + 1
        .TextMatrix(i, 0) = i
        .Row = i
        .Col = 1
        .CellPictureAlignment = flexPicAlignCenterCenter
        .CellChecked = flexUnchecked
        For j = 0 To Adodc2.Recordset.Fields.Count - 2
            .TextMatrix(i, j + 2) = Trim(Adodc2.Recordset.Fields(j))
        Next j
        Adodc2.Recordset.MoveNext
    Next i
End With
End Sub
Private Sub asPopup1_Click(Index As Integer, Cancel As Boolean)
Dim ReaderNum As String, i As Integer, a As Integer
Select Case Index
    Case 0
        Form20.Left = (Me.Width - Form20.Width) / 2
        Form20.Top = (Me.Height - Form20.Height) / 2
        Form20.Caption = "添加读者信息"
        Form20.Text1(5).Text = Date
        Form20.Show 1
    Case 1
        Form20.Left = (Me.Width - Form20.Width) / 2
        Form20.Top = (Me.Height - Form20.Height) / 2
        Form20.Caption = "修改读者信息"
        ReaderNum = Trim(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2))
        Form20.Adodc2.ConnectionString = Form1.Adodc1.ConnectionString
        Form20.Adodc2.RecordSource = "select * from reader where 读者编号 = '" & ReaderNum & "'"
        Form20.Adodc2.Refresh
        If Form20.Adodc2.Recordset.RecordCount > 0 Then
            For i = 0 To 1
                Form20.Text1(i).Text = Trim(Form20.Adodc2.Recordset.Fields(i))
            Next i
            For i = 2 To 3
                (i).Text = Trim(Form20.Adodc2.Recordset.Fields(i))
            Next i
            For i = 4 To 5
                Form20.Text1(i).Text = Trim(Form20.Adodc2.Recordset.Fields(i))
            Next i
            For i = 8 To 10
                Form20.Text1(i).Text = Trim(Form20.Adodc2.Recordset.Fields(i))
            Next i
            Form20.Image1.Picture = LoadPicture(App.Path & "\database\读者照片\" & Trim(Form20.Adodc2.Recordset.Fields("读者照片")))
        End If
        Form20.Show 1
    Case 2
        a = MsgBox("确定要删除该读者记录吗?", vbOKCancel Or vbQuestion, "删除提示")
        If a = vbOK Then
            ReaderNum = Trim(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2))
            Form20.Adodc2.ConnectionString = Form1.Adodc1.ConnectionString
            Form20.Adodc2.RecordSource = "select * from reader where 读者编号 = '" & ReaderNum & "'"
            Form20.Adodc2.Refresh
            Form20.Adodc2.Recordset.Delete
            ShowRecord
        End If
    Case 3
        a = MsgBox("确定要删除选中的读者记录吗?", vbOKCancel Or vbQuestion, "删除提示")
        If a = vbOK Then
            With MSHFlexGrid1
                For i = 1 To .Rows - 1
                    .Row = i
                    .Col = 1
                    If .CellChecked = flexChecked Then
                        ReaderNum = Trim(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2))
                        Form20.Adodc2.ConnectionString = Form1.Adodc1.ConnectionString
                        Form20.Adodc2.RecordSource = "select * from reader where 读者编号 = '" & ReaderNum & "'"
                        Form20.Adodc2.Refresh
                        Form20.Adodc2.Recordset.Delete
                    End If
                Next i
            End With
            ShowRecord
        End If
    Case 4
        PopupMenu SelectButton, , asPopup1(4).Left, asPopup1(4).Top + asPopup1(4).Height + 10
    Case 5
        Adodc2.RecordSource = "select * from reader where 截止日期 <='" & CStr(Date) & "'"
        Adodc2.Refresh
        ShowRecord
    Case 6
        Adodc2.RecordSource = "select * from reader"
        Adodc2.Refresh
        ShowRecord
    Case 7
        Unload Me
End Select
End Sub

Private Sub Command1_Click()
If Text1.Text = "" Then
    MsgBox "查询条件不能为空", vbOKOnly Or vbInformation, "提示信息"
    Text1.SetFocus
Else
    Select Case Flag
        Case 0
            If Check1.Value = 1 Then
                Adodc2.RecordSource = "select * from reader where 读者编号 like '%" & Trim(Text1.Text) & "%'"
            Else
                Adodc2.RecordSource = "select * from reader where 读者编号 = '" & Trim(Text1.Text) & "'"
            End If
        Case 1
            If Check1.Value = 1 Then
                Adodc2.RecordSource = "select * from reader where 读者姓名 like '%" & Trim(Text1.Text) & "%'"
            Else
                Adodc2.RecordSource = "select * from reader where 读者姓名 = '" & Trim(Text1.Text) & "'"
            End If
    End Select
    Adodc2.Refresh
    ShowRecord
End If
End Sub

Private Sub Form_Load()
Dim Key As String, Text As String
Dim i As Integer
Adodc1.ConnectionString = Form1.Adodc1.ConnectionString
Adodc1.RecordSource = "select * from readertype"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
TreeView1.ImageList = ImageList1
Key = "全部类型"
Text = "全部类型"
TreeView1.Nodes.Add , , Key, Text, 1
If Adodc1.Recordset.RecordCount > 0 Then
    Adodc1.Recordset.MoveFirst
    While Not Adodc1.Recordset.EOF
        Key = Trim(Adodc1.Recordset.Fields("读者类型名称"))
        Text = Key
        TreeView1.Nodes.Add , , Key, Text, 1
        Adodc1.Recordset.MoveNext
    Wend
End If
Option1(0).Value = True
Flag = 0
Check1.Value = 1
MSHFlexGrid1.BackColorFixed = 15983050
MSHFlexGrid2.BackColorFixed = 15983050
Adodc2.ConnectionString = Adodc1.ConnectionString
Adodc2.RecordSource = "select * from reader"
Adodc2.Refresh
With MSHFlexGrid1
    .FormatString = "序号|选中    "
    For i = 0 To Adodc2.Recordset.Fields.Count - 2
        .FormatString = .FormatString & "|" & Trim(Adodc2.Recordset.Fields(i).Name)
    Next i
    For i = 2 To 11
        .ColWidth(i) = 1200
        .ColAlignment(i) = flexAlignCenterCenter
    Next i
    .ColWidth(9) = 1600
    .ColWidth(10) = 3000
    .ColWidth(11) = 5000
    ShowRecord
End With
End Sub

Private Sub MSHFlexGrid1_Click()
If MSHFlexGrid1.Col = 1 Then
    If MSHFlexGrid1.CellChecked = flexChecked Then
        MSHFlexGrid1.CellChecked = flexUnchecked
    ElseIf MSHFlexGrid1.CellChecked = flexUnchecked Then
        MSHFlexGrid1.CellChecked = flexChecked
    End If
End If
End Sub

Private Sub OnlyViewSelect_Click()
Dim i As Integer
With MSHFlexGrid1
    For i = 1 To .Rows - 1
        If i + 1 > .Rows Then Exit For
        .Row = i
        .Col = 1
        If .CellChecked = flexUnchecked Then
            .RemoveItem i
            i = i - 1
        End If
    Next i
End With
End Sub

Private Sub Option1_Click(Index As Integer)
Flag = Index
End Sub

Private Sub RemoveSelect_Click()
Dim i As Integer
With MSHFlexGrid1
    For i = 1 To .Rows - 1
        .Row = i
        .Col = 1
        If .CellChecked = flexChecked Then
            .CellChecked = flexUnchecked
        End If
    Next i
End With
End Sub

Private Sub SelectAll_Click()
Dim i As Integer
With MSHFlexGrid1
    For i = 1 To .Rows - 1
        .Row = i
        .Col = 1
        .CellChecked = flexChecked
    Next
End With
End Sub

Private Sub SelectContrary_Click()
Dim i As Integer
With MSHFlexGrid1
    For i = 1 To .Rows - 1
        .Row = i
        .Col = 1
        If .CellChecked = flexChecked Then
            .CellChecked = flexUnchecked
        ElseIf .CellChecked = flexUnchecked Then
            .CellChecked = flexChecked
        End If
    Next i
End With
End Sub

Private Sub TreeView1_DblClick()
Dim Text As String
Text = Trim(Nod.Text)
If Text = "全部类型" Then
    Adodc2.RecordSource = "select * from reader"
    Adodc2.Refresh
Else
    Adodc2.RecordSource = "select * from reader where 读者类型 = '" & Text & "'"
    Adodc2.Refresh
End If
ShowRecord
End Sub

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Set Nod = Node
End Sub


[ 本帖最后由 yang3396789 于 2013-4-23 21:06 编辑 ]
搜索更多相关主题的帖子: EXCEL 
2013-04-23 21:02
快速回复:ACCESS数据库导入的数据不能使用
数据加载中...
 
   



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

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