OleDbParameter doesn't update value correctly

  • Thread starter Thread starter HungTrinh
  • Start date Start date
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
 
On Fri, 28 Jan 2005 11:33:54 +0700, HungTrinh wrote:
Hung,
Can you post the SP?
I think you are overwriting "AND" with "OR" and the last character ('D')
has remained from "AND". Just clear the field and then write the value, or
use a direct update command.

Ranjan

http://dotnetjunkies.com/weblog/dotnut
 
This is my SP in Access:

INSERT INTO IssueTracker_QueryClauses ( QueryId, BooleanOperator,
FieldName, ComparisonOperator, FieldValue, DataType )
VALUES ([@QueryId], [@BooleanOperator], [@FieldName],
[@ComparisonOperator], [@FieldValue], [@DataType]);

- When I debug, I see cmdClause.Parameters["@BooleanOperator"].Value
change correctly.
cmdClause.Parameters["@QueryId"].Value = queryId;
cmdClause.Parameters["@BooleanOperator"].Value =
clause.BooleanOperator;

But the value that is added to database is not correctly.

Thanks,
Hung
 
Back
Top