By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,572 Members | 1,516 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,572 IT Pros & Developers. It's quick & easy.

Q: Creating a table within the datasource

P: n/a
Hi

Is it possible to create a new table within an access database from within
VB? That is, I have an access database which has several tables. I would
like, from VB.NET, to create a new table using data from the other tables
(which I have done) but I want this table to be part of the original access
file.

Is this possible?

Some example code would be most appreciated.

Geoff
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Geoff Jones"

It is easy, I hope that this sample helps?

Cor

Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;" &
_
" Data Source=C:\db1.mdb;User Id=admin;Password=;")
Dim cmd As New OleDb.OleDbCommand("CREATE TABLE persons ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"BirthDate datetime," & _
"IdCountry int," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
conn.Open()
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
conn.Close()
End Sub
End Class
Nov 20 '05 #2

P: n/a
Many thanks Cor

Geoff

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eh**************@TK2MSFTNGP10.phx.gbl...
"Geoff Jones"

It is easy, I hope that this sample helps?

Cor

Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;" & _
" Data Source=C:\db1.mdb;User Id=admin;Password=;")
Dim cmd As New OleDb.OleDbCommand("CREATE TABLE persons ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"BirthDate datetime," & _
"IdCountry int," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
conn.Open()
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
conn.Close()
End Sub
End Class

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.