有一局域网,ACCESS数据库在其中一台中,我现在要在其它电脑VB中写程序对ACCESS数据库一个表增加30个单精度型字段,请问具体如何操作?另一个问题(有关查询条件的问题)也是一台电脑对另一台电脑上的ACCESS数据库中一个表进行查询(以时间进行查询),这个表中一天内有24条记录,也就是一个小时一条记录,有一个短日期字段和一个日期时间字段,我现在要做一个报表,这个报表中要有查询当天的24条记录再加上前一天的最后一条记录请问这个查询条件应该怎么写?

解决方案 »

  1.   

    第二个问题
       我认为你可以这样
           select * from 表 where sj='今天'
               union
           select max(sj),* from 表 where sj='昨天'
           还有一种方法,我没有试过
           select * from 表 where (sj='今天') or (sj='昨天' and max(sj))
      

  2.   

    我用的是DTPICKER.VALUE做为输入的查询时间值,查询当天的时间为DTPICKER.VALUE,前一天或后一天的时间怎么取呢?
      

  3.   

    cuilei197979(风) 感谢你回复了我所有提出的问题!:)
      

  4.   

    strSql="select sj,* from 表 where sj='" & DTPICKER.VALUE & "' Union select max(sj),* from 表 where sj='" & DTPICKER.VALUE -1 & "'"
      

  5.   

    1.参考:Private Sub Form_Load()
        '菜单“工程”-->"引用"-->"Microsoft ActiveX Data Objects 2.5 Library"
        '菜单“工程”-->"引用"-->Microsoft ADO Ext.2.7 for DDL ado Security
         Dim cat As ADOX.Catalog
         Set cat = New ADOX.Catalog
        cat.Create ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path & "\newdata.mdb" + ";")
        MsgBox "数据库已经创建成功!"
        Dim tbl As ADOX.Table
        Set tbl = New ADOX.Table
        tbl.ParentCatalog = cat
        tbl.Name = "MyTable"
        
        '增加一个自动增长的字段
        Dim col As ADOX.Column
        Set col = New ADOX.Column
        col.ParentCatalog = cat
        col.Type = ADOX.DataTypeEnum.adInteger ' // 必须先设置字段类型
        col.Name = "id"
        col.Properties("Jet OLEDB:Allow Zero Length").Value = False
        col.Properties("AutoIncrement").Value = True
        tbl.Columns.Append col, ADOX.DataTypeEnum.adInteger, 0
        
        '增加一个文本字段
        Dim col2 As ADOX.Column
        Set col2 = New ADOX.Column
        col2.ParentCatalog = cat
        col2.Name = "Description"
        col2.Properties("Jet OLEDB:Allow Zero Length").Value = False
        tbl.Columns.Append col2, ADOX.DataTypeEnum.adVarChar, 25
        
        '增加一个货币型字段
        Dim col4 As ADOX.Column
        Set col4 = New ADOX.Column
        col4.ParentCatalog = cat
        col4.Type = ADOX.DataTypeEnum.adCurrency
        col4.Name = "xx"
        tbl.Columns.Append col4, ADOX.DataTypeEnum.adCurrency
        
        '增加一个OLE字段
        Dim col5 As ADOX.Column
        Set col5 = New ADOX.Column
        col5.ParentCatalog = cat
        col5.Type = ADOX.DataTypeEnum.adLongVarBinary
        col5.Name = "OLD_FLD"
        tbl.Columns.Append col5, ADOX.DataTypeEnum.adLongVarBinary
        
        '增加一个数值型字段
        Dim col3 As ADOX.Column
        Set col3 = New ADOX.Column
        col3.ParentCatalog = cat
        col3.Type = ADOX.DataTypeEnum.adDouble
        col3.Name = "ll"
        tbl.Columns.Append col3, ADOX.DataTypeEnum.adDouble
        Dim p As ADOX.Property
        For Each p In col3.Properties
            Debug.Print p.Name & ":" & p.Value & ":" & p.Type & ":" & p.Attributes
        Next
        
        '设置主键
        tbl.Keys.Append "PrimaryKey", ADOX.KeyTypeEnum.adKeyPrimary, "id", "", ""
        cat.Tables.Append tbl
        MsgBox "数据库表:" + tbl.Name + "已经创建成功!"
        Set tbl = Nothing
        Set cat = Nothing
        
        Dim adocon As ADODB.Connection
        Set adocon = New ADODB.Connection
        adocon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\newdata.mdb;" & "Mode=Share Deny Read|Share Deny Write;Persist Security Info=False;Jet OLEDB:Database Password="
        Set cat = New ADOX.Catalog
        Set cat.ActiveConnection = adocon
        For i = 0 To cat.Tables.Count - 1
           Debug.Print cat.Tables(i).Name   '取出表名
           If cat.Tables(i).Name = "MyTable" Then
           For j = 0 To cat.Tables(i).Columns.Count - 1
              Debug.Print cat.Tables(i).Columns(j)    '取出列名
              Debug.Print cat.Tables(i).Columns(j).Type '取出数据类型
              For Each p In cat.Tables(i).Columns(j).Properties
                Debug.Print p.Type & p.Name & p.Attributes    '取出列的属性
              Next
           Next j
           
           End If
        Next i
        
        cat.Tables.Item("MyTable").Columns("ll").Properties("Jet OLEDB:Allow Zero Length").Value = True '设置零长度正确
        
        Set cat = Nothing
        adocon.Close
        Set adocon = Nothing
    End Sub