✅ Dapper Generic Repository Error in Insert Method (SOLVED)
ERROR: Microsoft.Data.SqlClient.SqlException: 'Must declare the scalar variable "@".'
Hello everyone, I'm coding a Generic Repository with Dapper (database: MSSQL). I coded the Get and Delete operations, but I am getting the above error in the Insert operation. How do I solve this error?
6 Replies
what is the value of
parameters
in the debugger?parameters: @Name, @[Order], @Id, @CreatedAt, @CreatedBy, @UpdatedAt, @UpdatedBy
@[Order] - is that valid?
Maybe its not valid. I didnt thought the error was for that. But if I wouldn’t use query.replace then it throws another error: Incorrect syntax near the keyword 'Order'. What should I do for that
Yes. You are correct. I deleted query.replace then I updated the code like all columns has bracket:
Then my new error is: : 'Cannot insert explicit value for identity column in table 'Category' when IDENTITY_INSERT is set to OFF
I hope i'll handle it. I'm happy to my error is changed khskshkhsk
Yes I did it now. Thanks a lot buddy @phaseshift. . Codes are successfully working now
I was getting this error because I also take the Id value as a parameter. I specified that it should not take the Id column and it was fixed.
glad you got it fixed 😁 I was only guessing - dont really know SQL 😮
ahahhahahhahah your guess is good 🙂