thelner Posted September 11, 2006 Posted September 11, 2006 (edited) Hi, im new to programming so pleaser bear with me :) Im trying to make a program that creates a table for every entry on a table(store) and inherits (store sample). But it has error. Can somebody please point out to me what im doing wrong....... Dim cmdstr As String = "" Dim rdstr As String = "" rdstr = "SELECT store FROM stores" con1.Open() con2.Open() Dim cmdread As New OleDbCommand(rdstr, con2) Dim objreader As OleDbDataReader = cmdread.ExecuteReader() Dim cmdmke As New OleDbCommand(cmdstr, con1) Do While objreader.Read() objreader.Read() cmdstr = "CREATE TABLE [" + objreader("store") + "] INHERITS [store sample]" Label1.Text = objreader("store") cmdmke.ExecuteNonQuery() <<<<<<<<<<< ERROR!!! Loop con1.Close() con2.Close() Edited September 11, 2006 by PlausiblyDamp Quote
Administrators PlausiblyDamp Posted September 11, 2006 Administrators Posted September 11, 2006 What error does it give? Also try the following Dim cmdstr As String = "" Dim rdstr As String = "" rdstr = "SELECT store FROM stores" con1.Open() con2.Open() Dim cmdread As New OleDbCommand(rdstr, con2) Dim objreader As OleDbDataReader = cmdread.ExecuteReader() Dim cmdmke As OleDbCommand Do While objreader.Read() objreader.Read() cmdstr = "CREATE TABLE [" + objreader("store") + "] INHERITS [store sample]" cmdmke = New OleDbCommand(cmdstr, con1) Label1.Text = objreader("store") cmdmke.ExecuteNonQuery() <<<<<<<<<<< ERROR!!! Loop con1.Close() con2.Close() Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
thelner Posted September 11, 2006 Author Posted September 11, 2006 An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll Quote
thelner Posted September 11, 2006 Author Posted September 11, 2006 I think my SQL statement is the problem. Can you please give me an example statement that creates a table then copies the content of another table. Dont know if i need to use INHERITS os CREATE TABLE AS. Proper syntax so that i could use it with vb.net please...........:) EX. "CREATE TABLE qwerty INHERITS yuiop" (which i know is wrong since it gives an error) Quote
Administrators PlausiblyDamp Posted September 11, 2006 Administrators Posted September 11, 2006 What database are you using? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
thelner Posted September 12, 2006 Author Posted September 12, 2006 What database are you using? MS Access.... Quote
Administrators PlausiblyDamp Posted September 12, 2006 Administrators Posted September 12, 2006 IIRC Access doesn't support the INHERITS keyword when creating a table. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
thelner Posted September 12, 2006 Author Posted September 12, 2006 Oww, thanks sir. What do you suggest i use then. To copy a table into another table. :) Quote
Puiu Posted September 12, 2006 Posted September 12, 2006 You can use Select * into New_Table from Old_Table Like this you will create automatically a new table with the same structure and the same data. However i don't think that it will keep the indexes, so check it out Quote
thelner Posted September 12, 2006 Author Posted September 12, 2006 It worked!!!! Thanks a lot!!!:) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.