我正在尝试使用下面的代码执行sql查询,但我收到“无法执行”错误。
我以为你可以帮帮我。
var sqlQuery = new StringBuilder();
sqlQuery.Append("SELECT t.* from VposTerminal t, VposAuthentication a Where a.MerchantNo = t.VposMerchant.MerchantNo and a.TerminalNo = t.TerminalNo and t.Status = 1");
sqlQuery.SqlAppendE("a", "ipAddress", ipAddress);
sqlQuery.SqlAppendE("t", "TerminalNo", terminalNo);
sqlQuery.SqlAppendE("t", "VposMerchant.MerchantNo", merchantNo);
sqlQuery.SqlAppendE("t", "Guid", posnetId);
sqlQuery.SqlAppendE("t", "VposMerchant.MerchantName", merchantName);
var query = Session.CreateSQLQuery(sqlQuery.ToString());
query.SetParameter("ipAddress", ipAddress);
query.SetParameter("TerminalNo", terminalNo);
query.SetParameter("VposMerchant.MerchantNo", merchantNo);
query.SetParameter("Guid", posnetId);
query.SetParameter("VposMerchant.MerchantName", merchantName);
错误:
"could not execute query\r\n[ SELECT t.* from VposTerminal t, VposAuthentication a Where a.MerchantNo = t.VposMerchant.MerchantNo and a.TerminalNo = t.TerminalNo and t.Status = 1 AND a.ipAddress = :p0 AND t.TerminalNo = :p1 AND t.VposMerchant.MerchantNo = :p2 AND t.Guid = :p3 AND t.VposMerchant.MerchantName = :p4 ]\r\n Name:ipAddress - Value:185.28.3.23 Name:TerminalNo - Value:67011071 Name:VposMerchant.MerchantNo - Value:6706598320 Name:Guid - Value:12730 Name:VposMerchant.MerchantName - Value:YKB TEST\r\n[SQL: SELECT t.* from VposTerminal t, VposAuthentication a Where a.MerchantNo = t.VposMerchant.MerchantNo and a.TerminalNo = t.TerminalNo and t.Status = 1 AND a.ipAddress = :p0 AND t.TerminalNo = :p1 AND t.VposMerchant.MerchantNo = :p2 AND t.Guid = :p3 AND t.VposMerchant.MerchantName = :p4]"
SqlAppendE:
public static StringBuilder SqlAppendE(this StringBuilder sb, string alias, string parameterName, object parameterValue)
{
if (!Validation.IsNullOrEmpty(parameterValue))
{
sb.Append(" AND ").Append(alias).Append(".").Append(parameterName).Append(" = :").Append(parameterName);
}
return sb;
}