Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Had this Code, that adds table in my database, but didn't add it into DataSet.
Simply i want to fetch the data from the table i created.
As the created table is not in DataSet, i can't fetch data from it.

Here the code i have.

VB
con.Open()
Dim dbSchema As DataTable = con.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, TextBox1.Text, "TABLE"})
con.Close()


If dbSchema.Rows.Count > 0 Then
      MsgBox("Table Exist")
Else

Dim cmd As New OleDb.OleDbCommand("CREATE TABLE [" + TextBox1.Text + "] ([Field1] TEXT(10), [Field2] TEXT(10))", con)
con.Open()
cmd.ExecuteNonQuery()
MessageBox.Show("Table Created Successfully")
con.Close()
End If


This is a working code to add new table in database, but not in DataSet.
Posted
Updated 12-Jan-16 11:06am
v2

1 solution

What you're saying does not make any sense. The code you presented only creates a table with a few fields in a database. There is nothing else you have to do, other than populating it with data, that will prevent you from querying the database and getting the data back.

There is no "DataSet" concept here.
 
Share this answer
 
Comments
Protonzz Baba 12-Jan-16 23:03pm    
ok. Then tell me how to populate it with data.

Look my intention is just clear, "Create every time a new table, add data into it and fetch it."
Dave Kreskowiak 12-Jan-16 23:51pm    
No, your intent was not clear at all. You're misusing terms causing confusion as to what you're wanting to do.

You already have most of the code to do an SQL INSERT statement. You just need the statement and create the parameter objects. Google for "C# SQL Parameterized queries" to get all kinds of examples on how to do it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900