Solved

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

Posted on 2006-06-21
9
306 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Video Player 12 28
How come this regular expression allows "e"? 14 45
Sort GridView by ID Descending 1 18
Amazon S3 .Net error 5 21
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!

821 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