H
HungTrinh
Hi,
I use OleDbCommand to insert a new row to Access database. We reuse instance of OleDbCommand more than one times.
example:
- The value of the first record is QueryID = 1 and BooleanOperator = "And"; Add to database correctly;
- The value of the second record is QueryID = 1 and BooleanOperator = "Or"; Add to database not correctly;
Here is the value in database:
QueryID BooleanOperator
1 And
1 Ord
The value of BooleanOperator is "Ord". Could you tell me how to solve this problem, please?
Here is the code:
OleDbCommand cmdClause = new OleDbCommand();
cmdClause.CommandType = CommandType.StoredProcedure;
cmdClause.CommandText = SP_QUERY_SAVEQUERYCLAUSE;
cmdClause.Parameters.Add( "@QueryId", OleDbType.Integer);
cmdClause.Parameters.Add( "@BooleanOperator", OleDbType.VarWChar, 50);
using (OleDbConnection cn = new OleDbConnection(this.ConnectionString)) {
cn.Open();
cmdClause.Connection = cn;
foreach (QueryClause clause in queryClauses) {
cmdClause.Parameters["@QueryId"].Value = queryId;
cmdClause.Parameters["@BooleanOperator"].Value = clause.BooleanOperator;
cmdClause.ExecuteNonQuery();
}
}
Thanks,
Hung
I use OleDbCommand to insert a new row to Access database. We reuse instance of OleDbCommand more than one times.
example:
- The value of the first record is QueryID = 1 and BooleanOperator = "And"; Add to database correctly;
- The value of the second record is QueryID = 1 and BooleanOperator = "Or"; Add to database not correctly;
Here is the value in database:
QueryID BooleanOperator
1 And
1 Ord
The value of BooleanOperator is "Ord". Could you tell me how to solve this problem, please?
Here is the code:
OleDbCommand cmdClause = new OleDbCommand();
cmdClause.CommandType = CommandType.StoredProcedure;
cmdClause.CommandText = SP_QUERY_SAVEQUERYCLAUSE;
cmdClause.Parameters.Add( "@QueryId", OleDbType.Integer);
cmdClause.Parameters.Add( "@BooleanOperator", OleDbType.VarWChar, 50);
using (OleDbConnection cn = new OleDbConnection(this.ConnectionString)) {
cn.Open();
cmdClause.Connection = cn;
foreach (QueryClause clause in queryClauses) {
cmdClause.Parameters["@QueryId"].Value = queryId;
cmdClause.Parameters["@BooleanOperator"].Value = clause.BooleanOperator;
cmdClause.ExecuteNonQuery();
}
}
Thanks,
Hung