I am getting an error when I try to fetch data from database and display in page.
Unclosed quotation mark after the character string.
sda.Fill(ds, "detail")
Here is my HTML and Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.PopulateBlog();
}
if (Request.QueryString["Id"] != null)
{
string Id = Request.QueryString["Id"] as String;
}
}
private void PopulateBlog()
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT [Heading],[Title],[Body] FROM [Guide] WHERE [Title] = '" + Request.QueryString["Id"] + "'";
cmd.Connection = con;
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
sda.SelectCommand = cmd;
sda.Fill(ds, "detail");
if (ds.Tables[0].Rows.Count > 0)
{
maintitle.Text = ds.Tables[0].Rows[0]["Heading"].ToString();
subtitle.Text = ds.Tables[0].Rows[0]["Title"].ToString();
body.Text = ds.Tables[0].Rows[0]["Body"].ToString();
}
}