Hi,
I am trying to run the following code -:
DataAccess Layer Function-:
public DataSet getContacts(string Country, string Product)
{
DataSet dsContact = new DataSet();
dsAdapter = new SqlDataAdapter();
string conString= ConfigurationSettings.AppSettings["ConnectionString"];
mySqlConn = new SqlConnection(conString);
mySqlConn.Open();
dsAdapter.SelectCommand.Connection = new SqlConnection(conString);
dsAdapter.SelectCommand.CommandText = "sp_getContactDetails";
dsAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
dsAdapter.SelectCommand.Parameters.Add("@Country", Country);
dsAdapter.SelectCommand.Parameters.Add("@Product", Product);
dsAdapter.Fill(dsContact);
return dsContact;
}
And the fron end code is-:
getContacts(string cntry, string prd)
{
dsContacts = obj.getContacts(cntry, prd);
if (dsContacts.Tables[0].Rows.Count > 0)
{
pnlHomePage.Visible=false;
pnlDispContacts.Enabled = true;
lblDispContacts.Text = dsContacts.Tables[0].Rows[0].ToString();
lblDispContacts.Visible=true;
}
else
{
//do something
}
}
The if condition is throwing the error -: System.NullReferenceException: Object reference not set to an instance of an object
The error is because there there are no tables in the dataset dsContacts;
First problem is the database code is throwing execption at the following line-:
"dsAdapter.SelectCommand.Connection = new SqlConnection(conString); "
can anyone show me where the problem is;
the conectivity is working fine for all the other functions except for this one.
Thank You;