Solved

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

Posted on 2006-06-21
9
307 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

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!

Question has a verified solution.

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

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

739 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