Tammu
asked on
Getting error while using QueryStringParameter in asp.net 2.0
Hi Experts,
i am trying to adding page title dynamically from a table which is stored in SQL database. here is my code but i am getting the error as :
Must declare the scalar variable "@ptitle"'
and the code is breaking at: SqlCmd.ExecuteNonQuery();
I have no idea where i am making the mistake.
can someone please guide. I appreciate it
i am trying to adding page title dynamically from a table which is stored in SQL database. here is my code but i am getting the error as :
Must declare the scalar variable "@ptitle"'
and the code is breaking at: SqlCmd.ExecuteNonQuery();
I have no idea where i am making the mistake.
can someone please guide. I appreciate it
protected void Page_Load(object sender, EventArgs e)
{
QueryStringParameter.Equals("Ptitle", @ptitle);
string query = "select * from PageInfo where Ptitle = @ptitle ";
SqlConnection myconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MySiteConnectString"].ConnectionString);
SqlCommand SqlCmd = null;
SqlCmd = new SqlCommand(query, myconnection);
SqlCmd.Connection.Open();
SqlCmd.ExecuteNonQuery();
SqlDataAdapter ad = new SqlDataAdapter(SqlCmd);
DataTable dt = new DataTable();
ad.Fill(dt);
title.InnerHtml = dt.Rows[0]["Ptitle"].ToString();
description.Attributes.Add("content" ,dt.Rows[0]["Desc"].ToString());
}
ASKER
Hi Sir,
i am getting this error now :
The SqlParameterCollection only accepts non-null SqlParameter type objects, not QueryStringParameter objects
what am i doing wrong.
Thanks i appreciate it.
i am getting this error now :
The SqlParameterCollection only accepts non-null SqlParameter type objects, not QueryStringParameter objects
what am i doing wrong.
Thanks i appreciate it.
In your code connection close() part is missing.
Check this post might useful.
http://www.tek-tips.com/viewthread.cfm?qid=949066&page=6
Check this post might useful.
http://www.tek-tips.com/viewthread.cfm?qid=949066&page=6
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks You SIr
ASKER
Thank you sir, You have nailed it. I appreciate it
Open in new window