Pete2003
asked on
C# Datasets and XML and data question
Hi All,
I have a problem with the new datasets and getting data from them.
The way I unbderstand , once you make a call to the database, the result is returned in a 'DataSet'. The contents however are not easily avaliable like in C++. The only access to data I found is the XML string.
I need to know how can I traverse the dataset and access specific values. I'm looking to make this dataset as much a recordset as I can. So my I have two questions:
1) Is there a way to treat the DataSet as a Recordset?
2) If not are there ny XML /parser classes in C# which I could use to create my own recordset.
Thanks
Peter
I have a problem with the new datasets and getting data from them.
The way I unbderstand , once you make a call to the database, the result is returned in a 'DataSet'. The contents however are not easily avaliable like in C++. The only access to data I found is the XML string.
I need to know how can I traverse the dataset and access specific values. I'm looking to make this dataset as much a recordset as I can. So my I have two questions:
1) Is there a way to treat the DataSet as a Recordset?
2) If not are there ny XML /parser classes in C# which I could use to create my own recordset.
Thanks
Peter
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Txs for the info ...
I do however have a problem as I do not use VB(your 1st post) or SQL Server ... I'll be using the Oracle classes connecting to an oracle server. As far as I see it Oracle only returns datasets, so therfore I will only be able to work with those.
I do however have a problem as I do not use VB(your 1st post) or SQL Server ... I'll be using the Oracle classes connecting to an oracle server. As far as I see it Oracle only returns datasets, so therfore I will only be able to work with those.
ASKER
Not to worry I found some dosumentation on oracle and ADO and figured out myself ... txs anyway
public void FillListBox()
{
SqlConnection myConnection = null;
SqlCommand myCommand;
SqlDataReader myReader;
try
{
String sQuery = @"SELECT * FROM Employees";
myConnection = new SqlConnection(connectionSt
myCommand = new SqlCommand(sQuery, myConnection);
myConnection.Open();
myReader = myCommand.ExecuteReader();
int nID;
String sFirstName, sLastName;
while (myReader.Read())
{
nID = myReader.GetInt32(myReader
sFirstName = myReader.GetString(myReade
sLastName = myReader.GetString(myReade
// Add item to listview
ListViewItem item = new ListViewItem(nID.ToString(
item.SubItems.Add(sFirstNa
item.SubItems.Add(sLastNam
listView.Items.Add(item);
}
initSucceeded = true;
}
catch ( Exception ex )
{
MessageBox.Show(parentForm
}
finally
{
if ( myConnection != null )
myConnection.Close();
}
}
However, if you are using DataSet, accessing it's rows is easy like accessing of array elements. In the followind sample employeesTable is reference to the table from DataSet:
employeesTable = dataSet.Tables[Employees];
public void FillListView()
{
try
{
String sID, sFirstName, sLastName;
DataRowCollection rows = employeesTable.Rows;
DataRow row;
// Read all rows in collection
for ( int i = 0; i < rows.Count; i++ )
{
row = rows[i];
// Extract fields from row
sID = row[fieldID].ToString();
sFirstName = row[fieldFirstName].ToStri
sLastName = row[fieldLastName].ToStrin
// Add item to listview
ListViewItem item = new ListViewItem(sID);
item.SubItems.Add(sFirstNa
item.SubItems.Add(sLastNam
listView.Items.Add(item);
}
}
catch ( Exception ex )
{
MessageBox.Show(parentForm
}
}
Decide what way is best for you.