Why I cannot use two DataSets?

  • Thread starter Thread starter Lupina
  • Start date Start date
L

Lupina

I want to read two xml files, each in other DataGrid; I do it like this :

....
DataSet *myDataSet;
DataSet *myDataSetUpdates;
....
private: System::Void btnLoadAll_Click(System::Object * sender,
System::EventArgs * e)
{

try
{
myDataSet->ReadXml("news.xml");
this->dataGridCommon->DataSource = myDataSet;
this->dataGridCommon->DataMember = ComboBoxDataGridNews->Text;
}
catch (Exception *e)
{
MessageBox::Show(e->Message);
}


try
{
myDataSetUpdates->ReadXml("updates.xml");
this->dataGridCommon->DataSource = myDataSetUpdates;
this->dataGridCommon->DataMember = ComboBoxDataGridUpdates->Text;
}
catch (Exception *e)
{
MessageBox::Show(e->Message);
}
}

When I use onlny one DataSet everything is OK, but with second DataSet I get
error :
"object reference not set to an instance of an object."

Please Help.
 
Lupina said:
I want to read two xml files, each in other DataGrid; I do it like this :

You haven't shown the code where your DataSets are actually created
(calling the DataSet constructor). My guess is that you've done this
for myDataSet, but not myDataSetUpdates.
 
You haven't shown the code where your DataSets are actually created
(calling the DataSet constructor). My guess is that you've done this
for myDataSet, but not myDataSetUpdates.

Here is the code :
public __gc class Form1 : public System::Windows::Forms::Form

{

public:

Form1(void)

{

InitializeComponent();

}


protected:

void Dispose(Boolean disposing)

{

if (disposing && components)

{

components->Dispose();

}

__super::Dispose(disposing);

}

private: DataSet *myDataSet;

private: DataSet *myDataSetUpdates;

private: System::Windows::Forms::TabControl * tabControl1;

.....

private: System::Void btnLoadAll_Click(System::Object * sender,
System::EventArgs * e)
{

try
{
myDataSet->ReadXml("news.xml");
this->dataGridCommon->DataSource = myDataSet;
this->dataGridCommon->DataMember = ComboBoxDataGridNews->Text;
}
catch (Exception *e)
{
MessageBox::Show(e->Message);
}


try
{
myDataSetUpdates->ReadXml("updates.xml");
this->dataGridCommon->DataSource = myDataSetUpdates;
this->dataGridCommon->DataMember = ComboBoxDataGridUpdates->Text;
}
catch (Exception *e)
{
MessageBox::Show(e->Message);
}
}
 
Lupina said:
Here is the code :

That's not *all* the code though - you've got a "...." line in there,
and I suspect that somewhere in the code you haven't posted there's a
call to the DataSet constructor. It may well be in Windows Forms
Designer code, unfortunately - but look for it, and see whether there's
an equivalent one for myDataSetUpdates.
 
Hi Lupina,

When you use only the second dataset, do you than get as well the error or
not?

Cor
 
Hi

I'm so inattentive; of course I didn't add line :

myDataSetUpdates = new DataSet(S"FedoraUpdates");

Great Thanks for advices
 
Back
Top