Just to let you know this is my first question im posting on this website, so please if I’ve missed anything just let me know. The problem im having is this, when the program runs im getting the following error message
Syntax error in FROM clause
The code is here
Dim dbProvider As String
Dim dbSource As String
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim MaxRows As Integer
Dim sql As String
Dim TableName As String
Dim TableCreate As New OleDb.OleDbCommand("CREATE TABLE [" & TableName & "](" & "ID INTEGER NOT NULL," & ")", con)
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM [" & TableName & "]", con)
Dim cb As New OleDb.OleDbCommandBuilder(da)
TableName = TbTableName.Text
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = E:\A2 Computing\Project\PasswordDatabase.mdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
da.Fill(ds, "NewTable")
MaxRows = ds.Tables("NewTable").Rows.Count
The Problem im having is at this line
da.Fill(ds, "NewTable")
Im not sure what I’ve missed out, Im guessing its something to do with the brackets when I declare tablecreate or da? =S Any help would be greatly appreciated. =)
You need to assign something to
TableNamebefore you use it, not after. Your current SQL isSELECT * FROM [], which is why you’re getting a syntax error there.Change the order of your code:
You also need to execute the
TableCreatestatement. IIRC, you useExecuteNonQueryto do so.Your table create SQL could be simplified, BTW:
Where are you actually connecting to the database? I don’t see an
OleDBConnectionanywhere in your code?Here’s a full example from the MSDN documentation for OleDBCommand.ExecuteNonScalar:
Also, you are aware that doing a
CREATE TABLEcreates a new, empty table, and therefore yourSELECT * FROMit won’t return anything but a singleNULLrow because you’re not inserting any data?