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!

create database

Status
Not open for further replies.

akshita

Programmer
Mar 26, 2002
25
0
0
IN
hi,

i want to create database using ado.
can u please tell me how to create database and define the tables using ado

i am using adodb


akshita
 
hi,

i am using access as a backend.now i want that instead of going to access and make database i will make it through by coding in vb


regards
akshita
 
Hey Akshita,

I have a good example for you. I removed the error handling and made the tables more generic for you but you'll get the drift. If you just place the code in your project it should work. just remember to reference the ADO type library and change the Data Source.
[tt]
Public Sub CreateDB()
Dim cat As New adox.Catalog
Dim tbl As New Table
Dim keyIndex As New adox.Index

cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\DB1.MDB"

' Open the Catalog.
cat.ActiveConnection = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\DB1.MDB"

'Add a new table to the newly created database

'table Customers

With tbl
'Add fields
.Name = "Customers"
.Columns.Append "CustName", adWChar, 25
.Columns.Append "CustID", adInteger, 6
.Columns.Append "ActiveCustomer", adBoolean, 1
.Columns.Append "Address", adWChar, 255
.Columns.Append "Phone", adWChar, 15
.Columns("Phone").Attributes = adColNullable
End With

keyIndex.Name = "CustNameIndex"
keyIndex.Unique = True
keyIndex.Columns.Append "CustName"
tbl.Indexes.Append keyIndex
cat.Tables.Append tbl
Set tbl = Nothing
Set keyIndex = Nothing

'table Orders
With tbl
'Add fields
.Name = "Orders"
.Columns.Append "OrderID", adInteger, 6
.Columns.Append "SysDT", adDate, 16
.Columns.Append "CustID", adInteger, 6
.Columns.Append "Details", adLongVarWChar, 2048
.Columns.Append "SalePrice", adInteger, 25
.Columns("SalePrice").Attributes = adColNullable
End With

keyIndex.Name = "OrderIDIndex"
keyIndex.Unique = True
keyIndex.Columns.Append "OrderID"
tbl.Indexes.Append keyIndex
Set keyIndex = Nothing

keyIndex.Name = "CustIDIndex"
keyIndex.Unique = True
keyIndex.Columns.Append "CustID"
tbl.Indexes.Append keyIndex
Set keyIndex = Nothing

keyIndex.Name = "SysDTIndex"
keyIndex.Unique = True
keyIndex.Columns.Append "SysDT"
tbl.Indexes.Append keyIndex

cat.Tables.Append tbl

'Clean up
Set cat = Nothing
Set tbl = Nothing
Set keyIndex = Nothing

End Sub[/tt]
Craig, mailto:sander@cogeco.ca

"Procrastination is the art of keeping up with yesterday."

I hope my post was helpful!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top