This code throws an error
Object reference not set to an instance of an object
Code:
string strSelect = "SELECT LookUpValuesID, [Description] FROM tblLookUpValues WITH(NOLOCK) WHERE LookUpTypeID = 2 ORDER BY [Description]";
using (SqlConnection cnSQL = new SqlConnection(strConnection))
using (SqlDataAdapter daValues = new SqlDataAdapter(strSelect, cnSQL))
{
SqlCommandBuilder cbValues = new SqlCommandBuilder(daValues);
DataSet dsValues = new DataSet();
daValues.Fill(dsValues);
MessageBox.Show(dsValues.Tables.Count.ToString());
chkbxLatches.DataSource = dsValues.Tables[0];
}
The MessageBox shows that there is 1 table in dsValues
. Why would I be getting that error if there is a table present? Is there something else I should be looking for?
Thanks for any suggestions.