+ Reply to Thread
Results 1 to 4 of 4

Thread: Diff between Dataset and DataTable

  1. #1
    korae is offline VB.NET Forum Newbie korae is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5
    Join Date
    Jan 2010
    Age
    24
    Posts
    22
    Reputation
    9

    Default Diff between Dataset and DataTable

    I have this code that fills my datagrid with data:

    Code:
    Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Network_Info.mdb"
                Dim myConnection As OleDbConnection = New OleDbConnection
                myConnection.ConnectionString = connString
                ' create a data adapter
                Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select DateRecorded As [Date Recorded], Format([TimeRecorded],'HH:MM:SS AM/PM') As [Time Recorded], Computer_Name As [Computer Name], Fastest_Download_Speed & ' Kb/s' As [Fastest Download Speed] , Fastest_Upload_Speed & ' Kb/s' As [Fastest Upload Speed], Average_Download_Speed & ' Kb/s' As [Average Download Speed], Average_Upload_Speed & ' Kb/s' As [Average Upload Speed], Total_Downloads & ' KB' As [Total Downloads], Total_Uploads & ' KB' As [Total Uploads], IP_Address, ElapsedTime As [Elapsed Time] from Computer_Connection_Info Order by DateRecorded, TimeRecorded", myConnection)
    
                Dim ds As DataSet = New DataSet
    
                da.Fill(ds, "Computer_Connection_Info")
    
                DataGrid1.DataSource = ds.DefaultViewManager
    I notice I'm using a dataset right? Then how am I suppose to fill my datagrid with data using a datatable? I've been very confused bout the topics in web like use a datatable or use a dataset bla bla bla...

  2. #2
    Paszt's Avatar
    Paszt is offline VB.NET Forum Moderator? Paszt a shining VB.NET star Paszt a shining VB.NET star Paszt a shining VB.NET star Paszt a shining VB.NET star Paszt a shining VB.NET star
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Raleigh, NC - USA
    Posts
    1,406
    Reputation
    197

    Default •◘•

    From MSDN:
    Quote Originally Posted by MSDN
    The DataSet, which is an in-memory cache of data retrieved from a data source, is a major component of the ADO.NET architecture. The DataSet consists of a collection of DataTable objects that you can relate to each other with DataRelation objects. You can also enforce data integrity in the DataSet by using the UniqueConstraint and ForeignKeyConstraint objects. For further details about working with DataSet objects, see DataSets, DataTables, and DataViews (ADO.NET).

    Whereas DataTable objects contain the data, the DataRelationCollection allows you to navigate though the table hierarchy. The tables are contained in a DataTableCollection accessed through the Tables property.
    Essential Reading: Multiple Forms Learn ASP.NET
    Whenever posting code, please enclose it in [code] tags to make it more readable. Follow this link to read about [code] tags.

  3. #3
    cjard's Avatar
    cjard is offline VB.NET Forum All-Mighty cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Apr 2006
    Age
    66
    Posts
    6,676
    Reputation
    927

    Default

    Quote Originally Posted by korae View Post
    I have this code that fills my datagrid with data:
    Read the DW3 link in my signature, section Creating a Simple Data App

    -> this code you have written is better off written for you by the IDE, leaving you to get on with more important things like writing the app. Read the tutorial above, it will make your life much easier (and make your code better!)

  4. #4
    Tom
    Tom is offline VB.NET Forum Idol Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET Tom master of VB.NET
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Aug 2005
    Posts
    746
    Reputation
    340

    Default

    A DataTable is similar to a table in your database. A DataSet is similar to the actual database where it can hold many tables within it. A DataGridView displays your data from your DataTable however you are setting the whole DataSet as the DataSource and it doesnt know which DataTable to display. You need to specify the DataTable within the DataSet.

    Code:
    Dim ds As DataSet = New DataSet
    
    da.Fill(ds, "Computer_Connection_Info")
    DataGrid1.DataSource = ds.Tables("Computer_Connection_Info")
    Or
    Code:
    Dim ds As DataSet = New DataSet
    
    da.Fill(ds, "Computer_Connection_Info")
    
    'Specify by table index within the dataset
    DataGrid1.DataSource = ds.Tables(0)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts