-4

I want to insert data in database in asp.net using c#,but it showing me this exception.

exception

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
G ABBAS
  • 23
  • 1
  • 8

2 Answers2

1

It is really hard to tell to solve your problem on an image but my money is on Table is a reserved keyword on TSQL part. You can use it with square brackets like [Table] but I do not recommend this. Change it to non-reserved word as a best option.

But much more important, you should always use parameterized queries. This kind of string concatenations are open for SQL Injection attacks.

And use using statement to dispose your connection and command automatically instead of calling Close method manually.

Based on your column name, ID should be numeric type instead of character. Do not have a bad habit to choose wrong data type.

Also do not store your passwords as a plain text. Read Best way to store password in database

Community
  • 1
  • 1
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
0

Query syntax is not correct so how can you fix it?

Steps:

  1. Copy command text(cmd.CommandText in debug mode)

  2. Open micro soft sql server management studio and open query analyzer and paste there.

  3. Run the query and you will find the cause.

  4. After fixing the syntax error there now you can construct query in same way for c# code

I trust it will help you. :)

Surya
  • 173
  • 4