我想开发可以与所有类型的数据库(Oracle、MySQL、SQLite)一起使用的通用应用程序。所以我从一个共同的地方为每个表单提供了不同的数据源。
而且我还想使用可以接受多个参数的参数化查询。我无法使用 DbParameter 传递多个参数,它适用于单参数查询,但不适用于许多参数。
所以请帮帮我...
dbconnect dc = new dbconnect();//class which contain data source name
DbConnection con;
DbCommand cmd;
DbDataReader dr;
DbProviderFactory df;
DataAdapter da;
df = DbProviderFactories.GetFactory(dbconnect.dbprovider);
con = df.CreateConnection();
con.ConnectionString = dbconnect.sqlstr;
con.Open();
cmd = df.CreateCommand();
cmd.CommandText = "update customer set" + " name='@name'," + "address='@address'," + "phone='@phone' " + "where code='@code';";
cmd.Connection = con;
DbDataAdapter daa = df.CreateDataAdapter();
daa.UpdateCommand = cmd;
DbParameter param = df.CreateParameter();
param.ParameterName = "@name";
param.Value = txtname.Text;
param.ParameterName = "@address";
param.Value = txtadd.Text;
param.ParameterName = "@phone";
param.Value = txtphone.Text;
param.ParameterName = "@code";
param.Value = txtcode.Text;
daa.UpdateCommand.Parameters.Add(param);
daa.UpdateCommand.ExecuteNonQuery();
**But this not working.**