Results 1 to 4 of 4

Thread: accessing/mofigying a local database in VB.net? *tears out hair*

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Posts
    3

    accessing/mofigying a local database in VB.net? *tears out hair*

    this is the one thing i never even looked into in VB6, i've done some database work in PHP using MySQL but that's it
    anyway, im trying to stumble through; i've found out how to create a DSN-less connection to the database (i think) with the following code:

    Dim objDs As DataSet
    Dim ObjDa As OleDbDataAdapter
    Dim sSQL As String
    sSQL = "SELECT * FROM Accounts"
    objDs = New DataSet()
    ObjDa = New OleDbDataAdapter(sSQL, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Environment.CurrentDirectory & "\db\database.mdb")


    im just trying to figure out how to retreive the result of the SQL statement,

    thanks for any assistance,
    check out some of my forums/websites:

    boardfleets, my online game being developed in PHP:
    http://boardfleets.gamealot.net

    STGN, no intro required for a lot of people :-)
    http://stgn.ugforums.com/vb/
    and
    http://stgn.ugforums.com/ for the site

    UGForums, my hosting company:
    http://www.ugforums.com

  2. #2

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Posts
    3
    bump
    check out some of my forums/websites:

    boardfleets, my online game being developed in PHP:
    http://boardfleets.gamealot.net

    STGN, no intro required for a lot of people :-)
    http://stgn.ugforums.com/vb/
    and
    http://stgn.ugforums.com/ for the site

    UGForums, my hosting company:
    http://www.ugforums.com

  3. #3
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    This ADO.NET is very confusing at first, but after you get it, its smooth sailing from then on.

    Try this

    'This fills the dataset with the info from the DB
    ObjDa.Fill(ObjDs)

    You will have to declare a datatable to get the tables from the database, and you also need to declare a datarow to get the row information.

    This is some code I wrote in C#, it should give you an idea what you need to do.

    Code:
                               CdDataAdapter.Fill(CdDataSet);
    			int index = CdDataSet.CD_Collection.Count;
    			CDCollection []CdColl = new CDCollection[index];
    
    			DataTable CdDataTable = CdDataSet.Tables[0];
    			
    			foreach(DataRow dr in CdDataTable.Rows)
    			{
    				for(int i = 0; i < index; i++)
    				{
    					CdColl[i] = new CDCollection();
    
    					CdColl[i].CdArtist = dr["RecordingArtistID"].ToString();
    					CdColl[i].CdLabel = dr["RecordingLabel"].ToString();
    					CdColl[i].CdNumberOfTracks = dr["NumberofTracks"].ToString();
    					CdColl[i].CdTitle = dr["RecordingTitle"].ToString();
    					CdColl[i].CdYear = dr["YearReleased"].ToString();
    					CdColl[i].CdGenre = dr["MusicCategoryID"].ToString();
    				}
    Dont gain the world and lose your soul

  4. #4
    pvb
    Guest
    Here are two examples of retrieving the results of a sql select using the datareader and dataset approaches:
    VB Code:
    1. Private Function MSAccess_DataReaderTest()
    2.     Dim sConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
    3.                 "C:\Program Files\Microsoft Visual Studio\VB98\BIBLIO2002.mdb"
    4.     Dim cnBiblio As New OleDbConnection(sConnString)
    5.     Dim drTitles As OleDbDataReader
    6.     Dim cmdTitles As New OleDbCommand("Select Top 10 * From Titles", cnBiblio)
    7.     cnBiblio.Open()
    8.     drTitles = cmdTitles.ExecuteReader()
    9.     While drTitles.Read()
    10.         Debug.WriteLine(drTitles.Item("title"))
    11.     End While
    12.     drTitles.Close()
    13.     cnBiblio.Close()
    14. End Function
    15.  
    16. Private Function MSAccess_DataSetTest()
    17.     Dim sConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
    18.                     "C:\Program Files\Microsoft Visual Studio\VB98\BIBLIO2002.mdb"
    19.     Dim cnBiblio As New OleDbConnection(sConnString)
    20.     Dim dsTitles As New DataSet()
    21.     Dim cmdSelect As New OleDbCommand("Select Top 10 * From Titles", cnBiblio)
    22.     Dim da As New OleDbDataAdapter(cmdSelect)
    23.     Dim drowTitle As DataRow
    24.  
    25.     cnBiblio.Open()
    26.     da.Fill(dsTitles, "Titles")
    27.     For Each drowTitle In dsTitles.Tables.Item("Titles").Rows
    28.         Debug.WriteLine(drowTitle.Item("title"))
    29.     Next
    30.     cnBiblio.Close()
    31. End Function

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