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

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input