string constring = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection(constring);
cmd.Connection = conn;
conn.Open();
cmd.CommandText = "sp_insert_data";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name",Session["nameforlogin"].ToString());
cmd.Parameters.AddWithValue("@decription", txtdesr.Text);
cmd.Parameters.AddWithValue("@url", txturl.Text);
SqlDataReader dr = cmd.ExecuteReader();
conn.Close();
Hai all,
i want to insert "name"(user can't enter his name in this page we need to retrieve from sessions).at the time i have this error Object reference not set to an instance of an object
how can i overome this
Thanks and Regards
Loading
Maruthi GongadiPosted Dec 31, 2015, 4:15 AM
Jignesh TrivediPosted Sep 17, 2013, 11:44 PM
I thing here your session value is null and you are trying to convert null value into string value...
check why your session value is null.
you can use Convert.Tostring() method to avoid error.
cmd.Parameters.AddWithValue("@Name",Convert.Tostring(Session["nameforlogin"]));
hope this will help you.
Iftikar HussainPosted Sep 17, 2013, 11:42 PM
Where you have assigned the value for Session["nameforlogin"]. Please make sure you have assign the session value in your page.
Regards,
Iftikar