Reputation: 197
How do I create a number field in access database using vb.net?
For example if I have this:
"CREATE TABLE [" & username_v.Text & "] ([test] TEXT(100))"
It creates my "test" as a TEXT field. How do I create a number field? Have tried NUMBER, INT, INTEGER and some others, but I get a syntax error...
How tried google, but can't find my answar...
Upvotes: 1
Views: 1688
Reputation: 7244
Try this
CREATE TABLE " & username_v.Text & " ([Test] TEXT(100));
This is the syntax for MS ACCESS
. Wrap the syntax with "" when executeing from a VB.NET
application
"CREATE TABLE " & username_v.Text & " ([Test] TEXT(100));"
Here is a example of different datatypes. Its recommended to Always use a Primary Key.
CREATE TABLE " & username_v.Text & "
(
[ID] AUTOINCREMENT,
[Test] TEXT(100),
[Integerfield] INTEGER,
[DateDatypeField] DATETIME,
);
Upvotes: 1
Reputation: 9322
You could use NUMBER
, although you mentioned already number and add the ;
at the end to be safe, like:
"CREATE TABLE [" & username_v.Text & "] ([test] TEXT(100), [ID] Number);"
Or INTEGER if you want an integer:
"CREATE TABLE [" & username_v.Text & "] ([test] TEXT(100), [ID] Integer);"
And if you want a primary key for that, you could do like this:
"CREATE TABLE [" & username_v.Text & "] ([ID] Integer NOT NULL, [test] TEXT(100), Primary Key([ID]) );"
Upvotes: 0
Reputation: 2992
Try
CREATE TABLE " & username_v.Text & " ([Test] TEXT(100), Total SHORT);
or
CREATE TABLE " & username_v.Text & " ([Test] TEXT(100), Total LONG);
see for other Access Data Types http://msdn.microsoft.com/en-us/library/ms714540(v=vs.85).aspx
Upvotes: 0