The variable name ‘x’ has already been declared. Variable names must be unique within a query batch or stored procedure.

The above error can result if you bound SQLDataSource to Formview ( or Gridivew – did not try GridView myself) where you are reusing a declare variable. For example you want to insert startDate and EndDate and all want to enter the difference of the two, you would so the following in SQL

Insert into mytable (startDate,EndDate,TotalDays)
values (@StartDate,@EndDate,datediff(d,@starDate,@EndDate))

You will get the above error because you are using @StartDate twice in the query. Also you are using @EndDateTwice in the query. To temporarily resolve the error, simply use an integer number in place of DateDiff function and the query will work.

This entry was posted in Troubeleshoot. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s