使用asp.net删除查询时出错

时间:2016-02-08 22:22:38

标签: c# sql asp.net ado.net

我尝试使用GridViews删除一些行。

 protected void Button1_Click(object sender, EventArgs e)
    {
        Session["ID_Oosby"] = GridView1.SelectedRow.Cells[0].Text;



        try
        {
            SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["RentCarConnectionString"].ConnectionString);
            conn1.Open();
            string deleteQuery = "Delete From from Klienci Where IDOsoby = @idosoby ";
            SqlCommand com2 = new SqlCommand(deleteQuery, conn1);
            com2.Parameters.AddWithValue("@idosoby", Session["ID_Osoby"]);
            com2.ExecuteNonQuery();
            conn1.Close();
        }
        catch (Exception ex)
        {
            Response.Write("Nie udąło sie usunac uzytkownika" + ex.ToString());
        }

    }

但是当我执行它时,我收到错误消息

System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'from'. w System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

知道出了什么问题吗?

1 个答案:

答案 0 :(得分:0)

将sql查询更改为:

string deleteQuery = "Delete From Klienci Where IDOsoby = @idosoby ";

你有两个导致异常的FROM子句。