0
Baglanti.FnkBaglan();
SqlCommand KayitSorgulaUsername = new SqlCommand("SELECT Username FROM User Where Username= @Username AND Username IS NOT NULL ", Baglanti.baglan);
SqlCommand KayitSorgulaMail = new SqlCommand("SELECT Mail FROM DatabaseProje.User Where Mail= @Mail  AND Username IS NOT NULL ", Baglanti.baglan);
KayitSorgulaUsername.Parameters.AddWithValue("@Username", TxtUyeOlUsername.Text);
KayitSorgulaMail.Parameters.AddWithValue("@Mail", TxtUyeOlMail.Text);
SqlDataReader VeriOkuUsername = KayitSorgulaUsername.ExecuteReader();
SqlDataReader VeriOkuMail = KayitSorgulaMail.ExecuteReader();

System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'User'.

This error appears after I entered the values to textboxes. How can I fix this error?

Alex
  • 13,024
  • 33
  • 62
ygzmglkc
  • 9
  • 1
  • 1
  • 8

3 Answers3

4

User is a reserved word in sql so use it with square brackets, so that it is considered as table name:

SELECT Username FROM [User]
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
1

User is a reserved keyword, so you must use square brackets to make it explicit that you mean the object named "User" it, i.e. use [User] instead of User. Refer to Link

Community
  • 1
  • 1
Pawan
  • 167
  • 12
1

Try to escape the keyword User with brackets: [User]

Fabian Stern
  • 376
  • 1
  • 9