Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading DataSet

How do I read data from a DataSet in WPF? I have a train schedule table with just 2 columns and I want to be able to read the departure times and calculate when the next train is leaving. For example, the time now is 12:29 and my application should tell me that next train will depart at 12:33.

I already googled left and right. I'm on .NET 3.5.

like image 980
Matt Avatar asked Jun 20 '11 10:06

Matt


People also ask

How do you read a dataset in a Kaggle notebook?

To read or write a data in Kaggle Kernel is the same as how you did in R or Python, the only thing to take note is the relative path to access the data. After data is added into notebook, click the dataset. Click on the "copy icon" to copy the path. Now you can paste it.


2 Answers

DataSet resembles database. DataTable resembles database table, and DataRow resembles a record in a table. If you want to add filtering or sorting options, you then do so with a DataView object, and convert it back to a separate DataTable object.

If you're using database to store your data, then you first load a database table to a DataSet object in memory. You can load multiple database tables to one DataSet, and select specific table to read from the DataSet through DataTable object. Subsequently, you read a specific row of data from your DataTable through DataRow. Following codes demonstrate the steps:

SqlCeDataAdapter da = new SqlCeDataAdapter(); DataSet ds = new DataSet(); DataTable dt = new DataTable();  da.SelectCommand = new SqlCommand(@"SELECT * FROM FooTable", connString); da.Fill(ds, "FooTable"); dt = ds.Tables["FooTable"];  foreach (DataRow dr in dt.Rows) {     MessageBox.Show(dr["Column1"].ToString()); } 

To read a specific cell in a row:

int rowNum // row number string columnName = "DepartureTime";  // database table column name dt.Rows[rowNum][columnName].ToString(); 
like image 142
KMC Avatar answered Sep 24 '22 02:09

KMC


If ds is the DataSet, you can access the CustomerID column of the first row in the first table with something like:

DataRow dr = ds.Tables[0].Rows[0]; Console.WriteLine(dr["CustomerID"]); 
like image 26
PeskyGnat Avatar answered Sep 22 '22 02:09

PeskyGnat