I want to develop generalized application which can works with all type of databases (Oracle, MySQL, SQLite). So I have provide different data source to the each form from one common place.
And I also want to use parametrized query who can accept multiple parameters. I am unable to to pass multiple parameters using DbParameter, it works fine with single parameter query but
not with many.
So please help me…
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.**
You’re only creating one parameter
etc…
You need to create a new
DbParameterfor each oneetc….
and add each one to the command.