Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database creation and table creation in ADO.NET

Status
Not open for further replies.

sacsac

Programmer
Dec 10, 2000
174
0
0
GB
I am new to ADO.NET, having been using ADO in VB6. Most things seem quite manageable, but I am having problems with two aspects. In my application I need to create a database if it does not exist, and in ADO I did it like this:

Dim cat As New ADOX.Catalog
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= FILENAME;)


and then created a table using:

Dim db As New ADODB.Connection
Dim RS As New ADODB.Recordset
Dim sql As String
sql = "CREATE TABLE People (RecNum INT NOT NULL PRIMARY KEY, Surname CHAR(50) NOT NULL);"
db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= FILENAME;
db.Open()

With RS
.ActiveConnection = db
.CursorType = ADODB.CursorTypeEnum.adOpenKeyset
.LockType = ADODB.LockTypeEnum.adLockPessimistic
.Open(sql)
RS = Nothing
End With

db.Close()
db = Nothing

I can still do this in .NET of course, but I'm sure that there must be a tidier way using ADO.NET.

Any help appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top