cmd.ExecuteReader()上的错误;

时间:2017-08-21 06:22:38

标签: c# asp.net gridview

我想通过在C#代码中选择gridview记录来移动rezomekh.aspx页面,这是我的代码:

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();
    }
}

我在这一行得到错误:

dr = cmd.ExecuteReader();

和错误文本是:

 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'.

0 个答案:

没有答案