awakenblueheart
Member
- Joined
- Aug 7, 2012
- Messages
- 5
- Programming Experience
- Beginner
Below is mycode to connect to Access database. Then it will create a table named "TABLENAME". Is there any way to make the table name based on user input..Please help my project here..
Dim strConnectString As String
Dim objConnection As OleDb.OleDbConnection
Dim strDbPath As String
Dim cmd As OleDb.OleDbCommand
Dim strDBName As String
strDBName = TextBox2.Text
Dim str As String
strDbPath = strDBName & ".mdb"
'==================================================
strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDbPath & ";"
objConnection = New OleDb.OleDbConnection(strConnectString)
str = "CREATE TABLE TABLENAME ([Haha] text(50) WITH Compression, " & _
"[Address1] text(150) WITH Compression, " & _
"[Address2] text(150) WITH Compression, " & _
"[City] text(50) WITH Compression, " & _
"[State] text(2) WITH Compression, " & _
"[PIN] text(6) WITH Compression, " & _
"[SIN] decimal(6))"
cmd = New OleDb.OleDbCommand(str, objConnection)
With objConnection
objConnection.Open()
cmd.ExecuteNonQuery()
End With
objConnection = Nothing
Dim strConnectString As String
Dim objConnection As OleDb.OleDbConnection
Dim strDbPath As String
Dim cmd As OleDb.OleDbCommand
Dim strDBName As String
strDBName = TextBox2.Text
Dim str As String
strDbPath = strDBName & ".mdb"
'==================================================
strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDbPath & ";"
objConnection = New OleDb.OleDbConnection(strConnectString)
str = "CREATE TABLE TABLENAME ([Haha] text(50) WITH Compression, " & _
"[Address1] text(150) WITH Compression, " & _
"[Address2] text(150) WITH Compression, " & _
"[City] text(50) WITH Compression, " & _
"[State] text(2) WITH Compression, " & _
"[PIN] text(6) WITH Compression, " & _
"[SIN] decimal(6))"
cmd = New OleDb.OleDbCommand(str, objConnection)
With objConnection
objConnection.Open()
cmd.ExecuteNonQuery()
End With
objConnection = Nothing