I want to move rezomekh.aspx page by choosing a record of gridview in C# code, here is my code:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
string usnam = e.CommandArgument.ToString();
try
{
if (e.CommandName == "rezome")
{
string query = "select from Ordertb where Username=@username";
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@username", usnam);
con.Open();
SqlDataReader dr;
dr = cmd.ExecuteReader();
dr.Read();
Session["usernamekh"] = dr["Username"].ToString();
//ViewState["userId"] = usId;
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("rezomekh.aspx");
}
}
finally
{
con.Close();
}
}
and i get error on this line:
dr = cmd.ExecuteReader();
and error text is:
Incorrect syntax near the keyword 'from'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'from'.