From MSDN:Originally Posted by MSDN
|
|
I have this code that fills my datagrid with data:
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...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
From MSDN:Originally Posted by MSDN
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.
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!)
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.
OrCode:Dim ds As DataSet = New DataSet da.Fill(ds, "Computer_Connection_Info") DataGrid1.DataSource = ds.Tables("Computer_Connection_Info")
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)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks