Donate

Incorrect Syntax Near % Sql Parameter In C#.NET and SQL Server

When writing sql statements in your business logic layer, you often want to append % which is a literal in your query. An example would be like this:
string query = "Select * from Patient where LastName like '" + "@family" + " %'";
However, this would give you an error, since the @family parameter is inside the tick marks that makes it a literal, but the % sign should be inside the tick marks. So, the correct sql syntax would be this way:
string query = "Select * from Patient where LastName like (@family + '%')";
Source: VBForums Link

Comments

Post a Comment

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Pass GUID As Parameter To Action Using ASP.NET MVC ContribGrid