[This question was accidentially placed in the wrong section. It should have been placed into "Data Controls".]
I fixed the problem.
Here were the requirements. I have a drop-down menu that a user selects an employee name. That employee name is then passed into the BindPrimaryGrid(string clientname) as a string parameter.
My problem was using a select parameter in the query was throwing an error. Here is the fix I came up with...
Session["myclient"] = clientname;
SqlConnection conn = new SqlConnection(GetConnectionString());
SqlCommand cmd = new SqlCommand("select ID, LastName, ClientName, ClientNum, Status from MyTable where ClientName LIKE '%' + @SearchName + '%'", conn);
cmd.Parameters.Add("@SearchName", SqlDbType.NVarChar);
cmd.Parameters["@SearchName"].Value = clientname;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
string myCount = dt.Rows.Count.ToString();
lblCountTotal.Text = myCount;
gvAll.DataSource = dt;
gvAll.DataBind();
}
Hopefully I have clarified any confusion and maybe this post will assist others with similar problems. :)
Thanks,
Alex Dove