aditya immadi

aditya immadi

  • NA
  • 205
  • 71.3k

Object Reference not set to an Instance of an Object.Error

Sep 17 2013 1:44 PM
       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

Answers (3)