ADO example

  • Thread starter Thread starter JR
  • Start date Start date
J

JR

Hi,

I have always worked with DAO in VB6. Now I want to change to dotnet and
ado.

In general I don't have problems with dotnet(2003) but I need a example for
a simple database (ex: 2 fields: name and adres)

1. making the database
2. Making a table
3. Making a index
4. Making a relation

with info lines
Who can help me
 
JR,

Beneath a sample. I changed a little bit an older sample from me.
This uses ADO for the creating of the Access database (what is not possible
using ADONET) and for the rest ADONET. The samples I have seen (not mine)
use only ADO for this kind of solutions.

The questions about making a table etc. you have in my opinion to explain,
because I have seen this can confuse. Do you mean a database datatable or a
dataset datatable in this?

Where for creating a database datatable relation etc. you would have to use
classic ADO again.

I hope this helps,

Cor

set a reference to COM adox ext 2.x for dll and security
\\\
Public Class Main
Public Shared Sub Main()
Dim catNewDB As New ADOX.Catalog
Dim fi As New IO.FileInfo("c:\db1.mdb")
If fi.Exists Then
If MessageBox.Show("Delete?", "Existing File db1.mdb", _
MessageBoxButtons.YesNo) = DialogResult.Yes Then
fi.Delete()
Else
Exit Sub
End If
End If
catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data
Source=C:\db1.mdb")
'To make tables we use Adonet
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.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
////
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top