Home Ask Login Register

Developers Planet

Your answer is one click away!

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;

            SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["RentCarConnectionString"].ConnectionString);
            string deleteQuery = "Delete From from Klienci Where IDOsoby = @idosoby ";
            SqlCommand com2 = new SqlCommand(deleteQuery, conn1);
            com2.Parameters.AddWithValue("@idosoby", Session["ID_Osoby"]);
        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?


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


Leave an answer

Quote of the day: live life