Solved

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

Posted on 2006-06-21
9
308 Views
Last Modified: 2010-04-16
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
Comment
Question by:ianinspain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
9 Comments
 
LVL 21

Accepted Solution

by:
MogalManic earned 500 total points
ID: 16950118
is the variable dataGrid1 null?  
0
 

Author Comment

by:ianinspain
ID: 16950257
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
 
LVL 3

Expert Comment

by:Bowmanje
ID: 16952072
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
Industry Leaders: 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!

 
LVL 3

Expert Comment

by:Bowmanje
ID: 16952078
Pardon, that should be dataGrid1.DataBind();

HTH,
Josh
0
 

Author Comment

by:ianinspain
ID: 16952633
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
 

Author Comment

by:ianinspain
ID: 16952738
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
 

Author Comment

by:ianinspain
ID: 16958795
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
 
LVL 21

Expert Comment

by:MogalManic
ID: 16959167
Read my 1st question!!!!
0
 

Author Comment

by:ianinspain
ID: 16967133
ahhh! yes you were right.... Assigning points now

Sorry about that... much appreciated

Ian
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question