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..

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.