mcrmg
asked on
Query question
Hi,
I am trying to run a query in code behind, because the query is simple, I do not want to create a sp just for that. Here is my code. It runs well without a parameter.
The result will be loaded into a dropdown list. thAnks
I am trying to run a query in code behind, because the query is simple, I do not want to create a sp just for that. Here is my code. It runs well without a parameter.
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ToString());
SqlCommand cmd = new SqlCommand("SELECT CategoryName from Category ORDER BY CategoryName=" + Session["sCMID"], con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable table = new DataTable();
da.Fill(table);
ContactName.DataSource = table;
ContactName.DataValueField = "CategoryName";
ContactName.DataTextField = "CategoryName";
ContactName.DataBind();
con.Close();
The result will be loaded into a dropdown list. thAnks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What is the question here?
ASKER
I need help with passing the parameter. thanks
ASKER
The code works fine
SqlCommand cmd = new SqlCommand("SELECT CategoryName from Category ORDER BY CategoryName=", con);
But when I try to add parameter, it does not work
SqlCommand cmd = new SqlCommand("SELECT CategoryName from Category ORDER BY CategoryName=" + Session["sCMID"], con);
thanks
SqlCommand cmd = new SqlCommand("SELECT CategoryName from Category ORDER BY CategoryName=", con);
But when I try to add parameter, it does not work
SqlCommand cmd = new SqlCommand("SELECT CategoryName from Category ORDER BY CategoryName=" + Session["sCMID"], con);
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I do not know what I was thinking... Where is the "WHERE clause"...............
ASKER
thanks