|
-
Mar 20th, 2003, 11:51 AM
#1
Thread Starter
Junior Member
Again DataBase Connection
Hello All
I am stucked with this simple problem.
I am going through the WROX book.But this code is not working
I am tring to open Access database and iterating through the datafield.
On compile there r so many errors
like adoConnection not defined
adoCommand is not defined
adoDatasetcommand is not defined ec..
I have written this code on button click.
please go through the following code and guide me if find any mistake
Or guide me if any other alternate to connectthe database and datafield operations
Thank u in advance
Here is My Code
References added in the project are:
adodb
system.data
system.windows.forms
Imports System.Data
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sConnectintring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\CAFE\Database\UserDatail.mdb;Persist Security Info=False"
Dim myConnection As New ADOConnection(sConnectintring)
Dim myCommand As New ADOCommand("Select * from MyData", myConnection)
Dim mtDatasetCommand As New AdodatasetCommand(myCommand)
Dim myDataet As New DataSet("Example1")
Try
myConnection.open()
mydatasetcommand.Filldataset(myDataset, "myData")
Dim rowcustomer As System.Data.DataRow
For Each rowcustomer In Mydataset.tables("myDAta").row
Console.WriteLine("Name:{0}", rowcustomer("Firstame"))
Next
Catch myexception As Exception
MessageBox.Show(myexception.ToString())
Finally
If myConnection.state = Data.dbobjects.open Then
myConnection.close()
End If
If Not mydataset Is Nothing Then
mydataset = Nothing
End If
End Try
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|