Solved

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

Posted on 2006-06-21
9
300 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
  • 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
 
LVL 3

Expert Comment

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

HTH,
Josh
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

948 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now