DbCommand.Parameters中缺少AddWithValue
技术问答
206 人阅读
|
0 人回复
|
2023-09-12
|
我正在同时建立一个处理方案MSsql和Sqlite的sqlwrapper,到目前为止,使用通用dbconnection,dataset和dataadapter没问题,但是用起来没问题,dbcommand( i+ \% U) J7 R) i) Z: W6 ~
parameters.add是唯一的选择。sqlcommand和sqlitecommand一样使用parameter.addwithvalue,但我不确定如何实现它。) s" y5 J8 J' L) c) O
例如,这是我的sqlitefactory:1 K8 X- B8 j( Q
public class SqlLiteFactory : SqlFactory{ public override DbConnection CreateConnection() { return new SQLiteConnection(ConfigurationManager.ConnectionStrings["ClientDBConnectionString"].ConnectionString); return new SQLiteConnection("Data Source=Resources\\qaqc.sqlite;Version=3"); } public override DataAdapter CreateAdapter(string command,DbConnection connection) return new SQLiteDataAdapter(command,connection as SQLiteConnection); } public override DbCommand CreateCommand() { return new SQLiteCommand(); }}这就是我的实现:# g8 G9 P4 f1 t4 z# B; c4 L
DbConnection c = SqlHandler.Instance.CreateConnection();DbCommand cmd = SqlHandler.Instance.CreateCommand();cmd.Connection = c;cmd.CommandText = "SELECT column FROM table WHERE syncstatus = 0 and UserName = @user GROUP BY column;";cmd.Parameters.Add("@user");cmd.Parameters["@user"].Value = SystemInformation.UserName;DbDataReader dr = cmd.ExecuteReader();在更具体的sqlcommand和sqlitecommand有一种方法.addwithvalue()这是我希望在父亲身上dbcommand类中有的方法。& |* H- p5 F8 r
8 c) I: D5 i, P' W8 l 解决方案: |
|
|
|
|
|