Creating Access Table in VB.Net

rickb

Member
Joined
Dec 31, 2002
Messages
17
Location
St. Louis, Missouri
Heres what Ive got : I have a button which, when clicked, needs to create a new table in an existing database. The name of the new table comes from a label text property, which gets its value from a combobox selection. Heres the code where my problem exists:

Dim oledbcon as New oledb.oledbconnection=("Provider=Microsoft.Jet.OLEDB.4.0; Data Source= <path to db>")
oledbcon.open

Dim oledbcom as New oledb.oledbcommand=("CREATE TABLE" & lblinstructor.text & "(Col1 Text, <plus more columns>)",oledbcon)
Debug.WriteLine(oledbcom.ExecuteNonQuery())

The error shows up at the last line ("Debug. . . ).

This works perfectly if the table name is a static name, but thats not what I need.

Can someone show me, or point me in the right direction, for creating a new table whos name is dynamic? Thanks in advance.
 
You need a space between TABLE and the name of the table. Right now, the double quote is next to the word TABLE. Try this instead:
Code:
Dim oledbcom as New oledb.oledbcommand=("CREATE TABLE " & lblinstructor.text &...

-Ner
 
Back
Top