'System.NullReferenceException' Error with DB Grid

  • Thread starter Thread starter Dotnet_Is_Love
  • Start date Start date
D

Dotnet_Is_Love

I am getting frustrated with this.
I have a winform where I doing following:


form_load:


SqlConnection objConn = new SqlConnection("Server
=(local);Database=mydatabase;uid=sa;pwd=;");
objConn.Open ();


SqlDataAdapter da = new SqlDataAdapter ("Select * from
my_table",objConn );

DataTable dt = new DataTable ("");


da.Fill ( dt);



When I run this I get following exception:


An unhandled exception of type 'System.NullReferenceException'
occurred in system.windows.forms.dll

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



I am not able to figure out the problem
 
set a break point on this line
SqlDataAdapter da = new SqlDataAdapter ("Select * from
my_table",objConn );

Use the debugger to find out if there are any errors in objConn. If it has
errors, it will be listed in the window. Then you can proceed from there
depending on whether or not there is an open error.

regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top