Moe DeShong
asked on
Changing database structure in vb.net
I need a resource that shows how to add/remove/change tables fields and most importantly relationships in an access database using vb.net.
Try this as a starter
All you need is a connection to the database and then basic T-SQL syntax:
Dim myScalarQuery As String = "ALTER TABLE Table1 ADD Field4 VARCHAR(20) NULL"
Dim myConnectionString As String = "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source='<path to access db>';User Id=admin;Password=;"
Dim myConnection As New OleDb.OleDbConnection(myCo nnectionSt ring)
Dim myCommand As New OleDb.OleDbCommand(myScala rQuery, myConnection)
myCommand.Connection.Open( )
myCommand.ExecuteNonQuery
myConnection.Close()
The above example adds a text field to an already created table.
As for relationships I'm not sure if you can create them with T-SQL. Alternatively you can use the Access Object adding a reference to the Microsoft Access Object Library.
Dim myScalarQuery As String = "ALTER TABLE Table1 ADD Field4 VARCHAR(20) NULL"
Dim myConnectionString As String = "Provider=Microsoft.Jet.OL
Dim myConnection As New OleDb.OleDbConnection(myCo
Dim myCommand As New OleDb.OleDbCommand(myScala
myCommand.Connection.Open(
myCommand.ExecuteNonQuery
myConnection.Close()
The above example adds a text field to an already created table.
As for relationships I'm not sure if you can create them with T-SQL. Alternatively you can use the Access Object adding a reference to the Microsoft Access Object Library.
ASKER
jerete,
I really need to know how to alter the relationship to award the points. I am trying to get rid of the autonumber fields and replace them with GUID fields which will require me to change the relationship. Thanks for the input
I really need to know how to alter the relationship to award the points. I am trying to get rid of the autonumber fields and replace them with GUID fields which will require me to change the relationship. Thanks for the input
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.