• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

dataGrid (winforms vs 2003) gives me a NullException when binding with a DS that has data

Hi there,

Can anyone help. I have a simply constructor that i build on a form which basically sets up a form to display some data in a datagrid

But it keeps giving me an error when assigning DataSource.... can anyone help?

here is the error
An unhandled exception of type 'System.NullReferenceException' occurred in Clientes.exe

And the code. (the form is called statement)

            public Statement(string title, DataSet statementData )
            {
                  
                  this.Text = title;
                  //dataGrid1.Read = statementData;

                  dataGrid1.DataSource=statementData.Tables["Record"];


            }

I also checked the row count of statementData.Tables["Record"] and it equals 6... so data is there..

I am missing something i know, but i don't know what it is...

It would be really appreciated if anyone can help

Thanks

Ian
0
ianinspain
Asked:
ianinspain
  • 5
  • 2
  • 2
1 Solution
 
MogalManicCommented:
is the variable dataGrid1 null?  
0
 
ianinspainAuthor Commented:
Hi . no dataGrid1 is a datagrid control in winforms vs 2003

but assigning the datasource to statementData.Tables["Record"]

gives the error msg... But the row count is 6... for statementData.Tables["Record"]

0
 
BowmanjeCommented:
Are you certain it is the assignment causing the problem?  I don't see a call to statmentData.DataBind(); in the constructor.  This would have to be done before attempting to display the data.

HTH,
Josh
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BowmanjeCommented:
Pardon, that should be dataGrid1.DataBind();

HTH,
Josh
0
 
ianinspainAuthor Commented:
Thanks Bowmanje,

Yes databinding is done like this in vs2003

dataGrid1.SetDataBinding(statementData, "Record");

I have a table Record in the dataset statementData

the exact error i get is this


An unhandled exception of type 'System.NullReferenceException' occurred in Clientes.exe

Additional information: Object reference not set to an instance of an object.


0
 
ianinspainAuthor Commented:
the error actually happens on this line

dataGrid1.SetDataBinding(statementData, "Record");

statementData is of type DataSet and was imported using ReadXML from an xml file.. It contains around 3 tables... 1 of the tables names is Record which i what i need to display

0
 
ianinspainAuthor Commented:
Ok i fixed it....

basically on my constructor i forgot to call InitializeComponent()

hence it didn't exist :-)

I will close the question if there are no objections..

Ian
0
 
MogalManicCommented:
Read my 1st question!!!!
0
 
ianinspainAuthor Commented:
ahhh! yes you were right.... Assigning points now

Sorry about that... much appreciated

Ian
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now