'System.NullReferenceException' Error with DB Grid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dotnet_Is_Love

    #1

    'System.NullReferenceException' Error with DB Grid

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


    form_load:


    SqlConnection objConn = new SqlConnection(" Server
    =(local);Databa se=mydatabase;u id=sa;pwd=;");
    objConn.Open ();


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

    DataTable dt = new DataTable ("");


    da.Fill ( dt);



    When I run this I get following exception:


    An unhandled exception of type 'System.NullRef erenceException '
    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
  • Alvin Bruney

    #2
    Re: 'System.NullRef erenceException ' Error with DB Grid

    set a break point on this line
    SqlDataAdapter da = new SqlDataAdapter ("Select * from
    my_table",objCo nn );

    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

    --


    -----------
    Got TidBits?
    Get it here: www.networkip.net/tidbits
    "Dotnet_Is_Love " <love_dotnet@ya hoo.com> wrote in message
    news:35a0aa74.0 310291228.27892 061@posting.goo gle.com...[color=blue]
    > I am getting frustrated with this.
    > I have a winform where I doing following:
    >
    >
    > form_load:
    >
    >
    > SqlConnection objConn = new SqlConnection(" Server
    > =(local);Databa se=mydatabase;u id=sa;pwd=;");
    > objConn.Open ();
    >
    >
    > SqlDataAdapter da = new SqlDataAdapter ("Select * from
    > my_table",objCo nn );
    >
    > DataTable dt = new DataTable ("");
    >
    >
    > da.Fill ( dt);
    >
    >
    >
    > When I run this I get following exception:
    >
    >
    > An unhandled exception of type 'System.NullRef erenceException '
    > 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[/color]


    Comment

    Working...