简体   繁体   English

参数化查询中的(?,?...?)或(@ field1,@ field2 ... @ fieldn)?

[英](?,?…?) or (@field1,@field2…@fieldn) in parmeterized queries?

Is this bad coding? 这是不好的编码?

I have a query 我有一个问题

INSERT INTO sometable (field1,field2...fieldn) VALUES (?,?,.....?)

Then 然后

cmd.Parameters.Add("TOFnr", OdbcType.Int, 10).Value = orderId;
cmd.Parameters.Add("LineNr", OdbcType.Int, 10).Value = maxLineNr;
cmd.Parameters.Add("Date", OdbcType.VarChar, 8).Value = rowHeader["Date"];

The code works, except there was an if-conditional around an Add, causing the data after that line to get into the wrong variable. 该代码有效,除了在Add周围有一个if条件,导致该行之后的数据进入错误的变量。

The placeholders ("TOFnr" etc.) is only used for the programmers reference, not used by the sql or c# itself, right? 占位符(“TOFnr”等)仅用于程序员引用,不是由sql或c#本身使用,对吗?

Isn't it less error-prone to used named parameters in the query? 在查询中使用命名参数不是很容易出错吗?

INSERT INTO sometable (field1,field2...fieldn) VALUES (@TOFnr,@LineNr,.....@fieldn)

It is c# connecting to borland paradox over odbc. 这是c#连接到odbc的borland悖论。

Isn't it less error-prone to used named parameters in the query? 在查询中使用命名参数不是很容易出错吗?

Yes, it is. 是的。 Unfortunately the ADO.NET ODBC driver doesn't allow named SQL parameters to be passed along in the SQL statement, so unfortunately for you, it is not possible using the ODBC driver. 遗憾的是,ADO.NET ODBC驱动程序不允许在SQL语句中传递命名的SQL参数,因此不幸的是,使用ODBC驱动程序是不可能的。

I am not an expert on Paradox, but there might be a driver specifically for Paradox which does allow named parameters. 我不是Paradox的专家,但可能有专门针对Paradox的驱动程序,它允许命名参数。 You might have more luck there. 你可能会有更多的运气。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Linq查询按字段1分组,对字段2计数并按连接集合的值之间的计数过滤 - Linq query to group by field1, count field2 and filter by count between values of joined collection 在C#中解析像Field1:val1,Field2:val2,Field3 = val3这样的字符串 - Parse string like Field1:val1,Field2:val2,Field3=val3 in c# SharePoint Lists.asmx UpdateListItems SET Field1 = NewValue WHERE Field1 = OldValue(按更新字段过滤) - SharePoint Lists.asmx UpdateListItems SET Field1=NewValue WHERE Field1=OldValue (filter by to be updated field) 将控件绑定到LINQ查询-找不到字段 - Binding controls to LINQ queries - cannot find field 在RavenDB LINQ查询中使用日期字段比较 - Using date field comparisons in RavenDB LINQ queries 具有字段优先级的嵌套查询和过滤器查询 - Nest queries with field priority and filter query 具有动态Order By的LINQ查询-一个以上字段 - LINQ Queries with dynamic Order By - more than one field 通过多个值查询字段的 Linq 语句转换为 in 语句 - Linq statement that queries field by multiple values gets converted to in statement 实体框架查询未命中过滤索引WHERE BIT字段= 0 - Entity Framework queries miss filtered index WHERE BIT field = 0 LINQ-2-SQL编译查询。 领域还是财产? - LINQ-2-SQL Compiled Queries. Field vs Property?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM