|
-
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
-
Mar 20th, 2003, 12:18 PM
#2
Frenzied Member
First take a look here: ConnectionStrings.com
If that doesn't help, maybe we need to look closer at the code.
~Peter

-
Mar 20th, 2003, 12:18 PM
#3
Hyperactive Member
Lose that book!!! it looks like it's based on Beta 1 or something, try something like the following:
VB Code:
Imports System
Imports System.Data
Imports System.Data.OleDb
Module MSAccessTest
Sub Main()
Test()
Console.Write("Press <Enter> to exit ...")
Console.ReadLine()
End Sub
Public Sub Test()
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=D:\AccessData\Authors.mdb"
Dim cn As New OleDbConnection(connString)
Dim cmdText As String = "Select * From Author Order By au_id"
Dim cmd As New OleDbCommand(cmdText, cn)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As DataSet = New DataSet("Authors")
da.Fill(ds)
Dim drow As DataRow
Dim dcol As DataColumn
For Each drow In ds.Tables(0).Rows
For Each dcol In ds.Tables(0).Columns
Console.Write(drow(dcol).ToString() & ",")
Next
Console.WriteLine()
Next
End Sub
End Module
-
Mar 20th, 2003, 12:23 PM
#4
definatly trash the book! That is like old as dirt and 99% obsolete.
-
Mar 20th, 2003, 12:24 PM
#5
Hyperactive Member
I just checked. Yes, i was ignorant when I purchased the "VB.NET Programming with the Public Beta" by Rockford Lhotka. I saw Rockford's name and immediately assumed it would be a valuable resource. I was way wrong on that one, the book was completely useless I think within minutes of hitting store shelves. The data access stuff in that waste of a book changed dramatically with beta 2 and the final release, your better off throwing that book away and stickin to online tutorials.
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
|