通过SQL为ms-Access创建一个Double的列

时间:2012-10-03 15:37:47

标签: sql vb.net visual-studio ms-access visual-studio-2005

我正在尝试使用SQL在我的ms-access表中创建列。我想将double从我的vb.net软件放入带有几个小数位的列中。我不确定用于启用访问接收小数位的正确列类型。如下所示我尝试long,但这似乎是长整数而不是长整数。从Microsoft.com看,我的选项如下:

  

CHAR [({size})] | CHARACTER [({size})] | LONGCHAR |简短| INT | INTEGER |长| OBJECT [NOT NULL] [TEMPORARY] [LOCALIZABLE] [HOLD]。

我当前的代码如下,sub运行一个访问数据库的函数。

    Public Sub AddColumnsToDatabase(ByVal Parameter)

    Dim scaleCounter
    Dim TableName As String
    Dim ColumnString As String
For scaleCounter = 2 To 2
        DatabaseSelector(scaleCounter)
        TableName = DataLocations(1, scaleCounter)

        cnnOLEDB = New OleDbConnection
        cnnOLEDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DataDirectoryName & DatabaseFileName
        cnnOLEDB.Open()

        cmdOLEDB.Connection = cnnOLEDB

        ColumnString = "PAR" & Format(Parameter, "0000")
        DatabaseConnectioninsert("ALTER TABLE " & TableName & " ADD " & ColumnString & " Long", "Non-Query")

        cnnOLEDB.Close()
        rdrOLEDB.Close()
end sub

 Public Function DatabaseConnectioninsert(ByVal Query As String, ByVal Task As String) As String
    On Error GoTo Err

    cmdOLEDB.CommandText = Query

    Select Case Task
        Case "Read Recordset"
            rdrOLEDB = cmdOLEDB.ExecuteReader()
            DatabaseConnectioninsert = "Read Recordset"
        Case "Read Scalar"
            DatabaseConnectioninsert = cmdOLEDB.ExecuteScalar
        Case "Non-Query"
            cmdOLEDB.ExecuteNonQuery()
            DatabaseConnectioninsert = "Non-Query"
    End Select


    Exit Function
Err:
    DatabaseConnectioninsert = "Error"


End Function

示例SQL查询是Query = "ALTER TABLE tabDataHourly ADD PAR0005 Long"

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

使用DOUBLE作为字段类型。

ALTER TABLE tabDataHourly ADD COLUMN PAR0005 DOUBLE;

您可以在此处找到有关Access DDL字段类型的更多信息:Field type reference - names and values for DDL, DAO, and ADOX