Monika Galińska February 2016

Error in delete query using asp.net

i trying delete some rows using 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());
        }

    }

But when i execute it I receive error message

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

Any idea what is wrong?

Answers


Harsh February 2016

Change sql query to:

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

You have two FROM clauses causing the exception.

Post Status

Asked in February 2016
Viewed 3,972 times
Voted 4
Answered 1 times

Search




Leave an answer