-2

I found people with the same problem, but none of their solutions helped me.

string checkuser = "select count(*) from Table where Username ='" + TextBox1.Text + "'";

It says "Incorrect syntax near the keyword 'Table'."

int temp = Convert.ToInt32(com.ExecuteScalar().ToString());

something about the ToString line

Owen Pauling
  • 11,349
  • 20
  • 53
  • 64

2 Answers2

1

Is your table actually called "Table"? If so, I'd recommend choosing a different name. If you really must call it "Table", then escape it with backquotes:

select count(*) from `Table` where Username = @Username

Also, you really should not insert the raw value from your textbox into a SQL query. That makes you prone to SQL injection attacks. Instead, you should make a @Username parameter for the query and pass the value through the parameter.

AJ Richardson
  • 6,610
  • 1
  • 49
  • 59
  • yes its the Tables name is Table i didnt think that throu...ill give it a shot. its a school project it wont go online! – user4907625 May 16 '15 at 20:01
  • Also, see [this answer](http://stackoverflow.com/a/13581064/1299394) for how to add SQL parameters to a mysql query – AJ Richardson May 16 '15 at 20:03
  • do i need to make a new Table or i can just rename it? – user4907625 May 16 '15 at 20:09
  • You should be able to just rename it. Making a new table works, too. – AJ Richardson May 16 '15 at 20:09
  • i cant get it to load the new table and forget the old that i deleted.. im going to start it all over again tomorow and if the problem exits i will post the full code. – user4907625 May 16 '15 at 20:22
  • So i redid the whole program and at the beginging i changed it to Net.Framework 4 i was useing the newest and some codes are diferent in that one! And i used a diferent table name! – user4907625 May 20 '15 at 15:09
0

If your table name is table then it is causing error because the table is use as a keyword by sql use something like this

select count(*) from [Table] where Username = '" + TextBox1.Text + "'";
R P
  • 348
  • 2
  • 15