0

here is my code that is giving me the error(just this section)

        InitializeComponent();
        String sqlString = "SELECT firstName, lastName FROM ClubMembers";

        //database connections and commands
        String stConn = App.getConnectionString();
        DataTable data = App.getGenericData(sqlString);


        //get data and put into list box
        for(int i=0; i<data.Rows.Count; i++)
        {
            string d1 = data.Rows[i]["lastName"].ToString() + ", " + data.Rows[i]["firstName"].ToString();
            listboxMembers.Items.Add(d1);
        }

I am getting the error inside the for part...either the int i=0 or the i<data.rows.count....not sure exactly why though

the error is : Object reference not set to an instance of an object.

it is pointing to the i=0 but the next section is highlighted...so not sure exactly which is causing the error....help..

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Mitja Bonca
0

Most likely data is null. Can your method App.getGenericData return null and if so in what situation? Try wrapping the for-loop into an if-statement that reads if (data != null) and step through the code with the debugger to see what happens.

Edited by darkagn: Tried to use manual [icode] tags rather than the toggle button provided, sorry

0

Exactly what darkagn said. Variable "data" is null. Your dataTable do not get fill up. Check like he expalined.
The method "DataTable data = App.getGenericData(sqlString);" does not return anything. Check that method.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.