I am creating a Books website i have made an books page in which i have given edit books page link when i click on that link a update form should open based on that books id from the database and that update form should be filled with pre entered details from the database.
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WEbApp
{
    public partial class Edit_Books : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename="ConnectionString";Integrated Security=True");
        protected void Page_Load(object sender, EventArgs e)
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
            con.Open();
            int id = Convert.ToInt32(Request.QueryString["bkid"].ToString());
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select * from Books where bkid="+id+"";
            cmd.ExecuteNonQuery();
            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            foreach(DataRow dr in dt.Rows)
            {
                Textbox1.Text = dr["book_name"].ToString();
                Textbox2.Text = dr["book_author"].ToString();
                Textbox3.Text = dr["book_publication"].ToString();
            }
        }
    }
}
When I run the upper code I get an error on this line:
int id = Convert.ToInt32(Request.QueryString["bkid"].ToString());
Object reference not set to an instance of an object.
 
     
    