3
Answers

System.Data.SqlClient.SqlException: Incorrect syntax near '

    SqlConnection con = new SqlConnection("Data Source=APPLE;Initial Catalog=sam;Integrated Security=True");
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            con.Open();
            string str1 = "DELETE * FROM AU_Delete";
            cmd.CommandText = str1;
            cmd.ExecuteNonQuery();
            con.Close();
           

This is  my coding for delete button it's showing error : Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '*'.

what is the problem in my coding?

Answers (3)

0
Photo of Santhosh Kumar Jayaraman
NA 9.9k 2.3m 12y
When You are deleting records,

You can write query as

delete table AU_Delete

or
delete from table au_Delete.

you have to use * only in select queries.

try this

 SqlConnection con = new SqlConnection("Data Source=APPLE;Initial Catalog=sam;Integrated Security=True");
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            con.Open();
            string str1 = "DELETE  AU_Delete";
            cmd.CommandText = str1;
            cmd.ExecuteNonQuery();
            con.Close();
          

0
Photo of Hemant Kumar
NA 3k 215.2k 12y
Mohammed Shamsheer,

you can't write '*' for the delete Statements

string Query="delete from AU_DELETE";
0
Photo of Naresh Avari
NA 811 1.6m 12y
Hi,

Remove '*' from your SQL Query and use

string str1 = "DELETE FROM AU_Delete";

You don't need to specify '*' for DELETE statement.