Results 1 to 5 of 5

Thread: Again DataBase Connection

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2002
    Location
    Mumbai
    Posts
    31

    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

  2. #2
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Thumbs up

    First take a look here: ConnectionStrings.com

    If that doesn't help, maybe we need to look closer at the code.
    ~Peter


  3. #3
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    Lose that book!!! it looks like it's based on Beta 1 or something, try something like the following:
    VB Code:
    1. Imports System
    2. Imports System.Data
    3. Imports System.Data.OleDb
    4.  
    5. Module MSAccessTest
    6.  
    7.     Sub Main()
    8.         Test()
    9.         Console.Write("Press <Enter> to exit ...")
    10.         Console.ReadLine()
    11.     End Sub
    12.  
    13.     Public Sub Test()
    14.         Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    15.                                    "Data Source=D:\AccessData\Authors.mdb"
    16.         Dim cn As New OleDbConnection(connString)
    17.         Dim cmdText As String = "Select * From Author Order By au_id"
    18.         Dim cmd As New OleDbCommand(cmdText, cn)
    19.         Dim da As New OleDbDataAdapter(cmd)
    20.         Dim ds As DataSet = New DataSet("Authors")
    21.         da.Fill(ds)
    22.         Dim drow As DataRow
    23.         Dim dcol As DataColumn
    24.  
    25.         For Each drow In ds.Tables(0).Rows
    26.             For Each dcol In ds.Tables(0).Columns
    27.                 Console.Write(drow(dcol).ToString() & ",")
    28.             Next
    29.             Console.WriteLine()
    30.         Next
    31.  
    32.     End Sub
    33.  
    34. End Module

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    definatly trash the book! That is like old as dirt and 99% obsolete.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    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
  •  



Click Here to Expand Forum to Full Width