Hi,
Few months ago I was trying to remove the primary key from my query's parameters, so with some help of you guys I did. However I was using stored procedures, but I was forced to build the sql string into my code, also without the primary key.
When I tried to remove the PK, I got a problem.
Example:
Code:
string sqlCommand = "INSERT INTO <[ CurrentEntityName ]> " +
"<[If HasFields ]><[ Foreach EntityField Comma ]><[ If Not IsPrimaryKey ]><[ EntityFieldName ]><[ EndIf ]><[ NextForeach ]><[EndIf]> " +
"VALUES " +
"(<[If HasFields]><[ Foreach EntityField Comma ]><[ If Not IsPrimaryKey ]>@<[ EntityFieldName ]><[ EndIf ]><[ NextForeach ]><[EndIf]>)";
The Result:
Code:
string sqlCommand = "INSERT INTO Bank " +
", BankID, Name" +
"VALUES " +
"(, @BankID, @Name)";
The comma is controlled by the ForEach loop and any expression inside the loop is not verified before insert or not the comma. In this case the comma is always printed.
You have some suggestion to solve this problem using TDL tags?
Wondering I realize that a simple way to solve this problem could be add Not into the ForEach loop like <[ ForEach Not PrimaryKeyEntityField ]>, then the comma will be properly printed.
Cheers.