-
Jul 11th, 2010, 10:56 AM
#1
Thread Starter
Addicted Member
Add table to database
Hey,
I have database called 'BCN.mdb'
the database includes a table called "BCN_Table"
I want to add a table while program running with DAL
something like:
Code:
Dim selectCommand As String = "add table " & TableName & " to file " & FileName
Try
Dim dataAdapter As New OleDbDataAdapter(selectCommand, oleDbConnection)
Dim dataSet As New DataSet
dataAdapter.Fill(dataSet)
Return dataSet
Catch
Throw
End Try
thank you all
-
Jul 11th, 2010, 11:31 AM
#2
Re: Add table to database
For a SQL Server Database, you can use the following:
http://www.tizag.com/sqlTutorial/sqlcreate.php
As for whether that will work on an Access Database, I am really not sure.
Gary
-
Jul 11th, 2010, 03:40 PM
#3
Addicted Member
Re: Add table to database
Something like this (Although this used ADOX?)
Code:
Dim ADOXtable As New ADOX.Table
Dim ADOXindex As New ADOX.Index
ADOXcatalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FILEPATH;Jet OLEDB:Database Password=PASSWORD")
ADOXcatalog.ActiveConnection = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FILEPATH;Jet OLEDB:Database Password=PASSWORD")
ADOXtable.Name = "tblName"
ADOXtable.Columns.Append("ID", ADOX.DataTypeEnum.adInteger)
ADOXtable.Columns.Append("field2", ADOX.DataTypeEnum.adVarWChar)
ADOXtable.Columns.Append(field3", ADOX.DataTypeEnum.adVarWChar)
ADOXcatalog.Tables.Append(ADOXtable)
ADOXindex.Name = "IDIndex" 'name of index
ADOXindex.Columns.Append("ID")
ADOXtable.Indexes.Append(ADOXindex)
-
Jul 11th, 2010, 08:38 PM
#4
Re: Add table to database
Why exactly do you want to add the table in the first place? Adding tables from applications is not unheard of but it's not a common thing to do. Most people I've seen post about it were doing the wrong thing, so I'm interested to know your reason.
-
Jul 12th, 2010, 05:55 AM
#5
Re: Add table to database
Originally Posted by gep13
As for whether that will work on an Access Database, I am really not sure.
CREATE TABLE works against any database that supports some form of SQL (and, IMO, is both the easiest and best, way to create a new table programmtically.)
-
Jul 12th, 2010, 06:42 AM
#6
Re: Add table to database
Good to know, thanks Hack.
It has been ages since I have done anything with Access, and I wasn't sure
Gary
-
Jul 12th, 2010, 11:14 AM
#7
Thread Starter
Addicted Member
Re: Add table to database
What do you (all of you guys) say about this?
Code:
Public Sub AddTableToDatabase(ByVal FileName As String, ByVal dataTable As DataTable)
Dim Cmd As OleDbCommand
Dim objCmd As New OleDbCommand
Dim selectCmd As String = "CREATE TABLE " & dataTable.TableName & " (" & MakeNewTableSQLString(dataTable) & ")" '"[Id] COUNTER, [Stock Code] TEXT(10), [Account Number] TEXT(6))"
Dim Con = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;data source=" & FileName)
Cmd = New OleDbCommand(selectCmd, Con)
Con.Open()
objCmd = New OleDbCommand(selectCmd, Con)
objCmd.ExecuteNonQuery()
Con.Close()
End Sub
-
Jul 12th, 2010, 11:41 AM
#8
Re: Add table to database
-
Jul 12th, 2010, 11:52 AM
#9
Re: Add table to database
Since Counter is not a valid data type I would say no it does not work.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Jul 12th, 2010, 02:58 PM
#10
Thread Starter
Addicted Member
Re: Add table to database
-
Jul 13th, 2010, 01:06 AM
#11
Re: Add table to database
Gary,
It would seem like for an Access Database, Counter is a valid DataType:
http://msdn.microsoft.com/en-us/libr...40(VS.85).aspx
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|