I have to use connection string for my query, but I am getting an error
object reference not set to an instance of an object.
This is my code:
string strSql = "select first_name + ' ' + last_name name, email from user_mst where mkey in (" + Session["UserId"].ToString() + ")";
DataTable table = new DataTable();
using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString()))
{
conn.Open();
using (SqlDataAdapter dbdata = new SqlDataAdapter(strSql, conn))
{
dbdata.Fill(table);
}
conn.Close();
}
I get error at
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString()))
but my connections seems to be exactly fine.