Array of datasets....

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I am trying to do the following:

I have a db column that stores xml inside
I want to create one dataset for each field with xml ( this means that I
don't know how many datasets I will have...) anyway I had a great idea, and
array of datasets, but it's not working...here is the code:

OdbcCommand oCmd = new OdbcCommand("SELECT * FROM tb_s57_terminals WHERE
class = 7",oConn);
OdbcDataReader dr;
oCmd.Connection.Open();
dr = oCmd.ExecuteReader();
DataSet[] dsUpdate = new DataSet[nTerminals];
int i = 0;
while (dr.Read())
{
try
{
using (StringReader sr = new StringReader(dr.GetString(4)))
{
dsUpdate.ReadXml(sr);
}
}
catch(Exception exc)
{
}
i++;
}
oCmd.Connection.Close();

the var nTerminals is a count to the fields on the database that have class
4...

The problem is an object reference not set to an instance of an object....

It catchs it on the try.... can someone tell me why?
 
"Diogo Alves - Software Developer"
Hi all,
DataSet[] dsUpdate = new DataSet[nTerminals];
dsUpdate.ReadXml(sr);


The problem is an object reference not set to an instance of an object....



I think your error is due to the fact that you never actually CREATE a
dataset at each index of dsUpdate.
DataSet[] dsUpdate = new DataSet[nTerminals];
only creates the array itself - it does not fill each index with instances
of datasets.
Just above your call to ReadXml, try adding:

dsUpdate = new DataSet();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top