I am trying to create columns within my ms-access table using SQL. I want to put double
s from my vb.net software into the column with several decimal places. I am unsure of the correct column type to use to enable access to receive the decimal places. As below I have tried long
but this seems to be long integer rather than a long number. From Microsoft.com it would appear that my options are the following:
CHAR [( {size} )] | CHARACTER [( {size} )] | LONGCHAR | SHORT | INT | INTEGER | LONG | OBJECT [NOT NULL] [TEMPORARY] [LOCALIZABLE] [HOLD]
.
My current code is below, the sub runs a functions to access the database.
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
An example SQL query is Query = "ALTER TABLE tabDataHourly ADD PAR0005 Long"
Thanks for your help
Use DOUBLE
for the field type.
ALTER TABLE tabDataHourly ADD COLUMN PAR0005 DOUBLE;
You can find more information about Access DDL field types here: Field type reference - names and values for DDL, DAO, and ADOX