This is a multi-part message in MIME format.

------=_NextPart_000_0049_01C5052D.3F21E3E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,

I use OleDbCommand to insert a new row to Access database. We reuse =
instance of OleDbCommand more than one times.=20
=20
example:
- The value of the first record is QueryID =3D 1 and =
BooleanOperator =3D "And"; Add to database correctly;
- The value of the second record is QueryID =3D 1 and =
BooleanOperator =3D "Or"; Add to database not correctly;
=20
Here is the value in database:
QueryID BooleanOperator
1 And
1 Ord =20
=20
The value of BooleanOperator is "Ord". Could you tell me how to =
solve this problem, please?

Here is the code:

OleDbCommand cmdClause =3D new OleDbCommand();

cmdClause.CommandType =3D CommandType.StoredProcedure;
cmdClause.CommandText =3D SP_QUERY_SAVEQUERYCLAUSE;

=20
cmdClause.Parameters.Add( "@QueryId", OleDbType.Integer);
cmdClause.Parameters.Add( "@BooleanOperator", OleDbType.VarWChar, =
50);

using (OleDbConnection cn =3D new =
OleDbConnection(this.ConnectionString)) {
cn.Open();
cmdClause.Connection =3D cn;
foreach (QueryClause clause in queryClauses) {
cmdClause.Parameters["@QueryId"].Value =3D queryId;
cmdClause.Parameters["@BooleanOperator"].Value =3D =
clause.BooleanOperator;
=20
cmdClause.ExecuteNonQuery();
}
}

Thanks,
Hung
------=_NextPart_000_0049_01C5052D.3F21E3E0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1479" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; I use OleDbCommand =
to insert a=20
new row to Access database.&nbsp;We&nbsp;reuse instance of=20
OleDbCommand&nbsp;more than one times. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
example:</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-=20
The value of the first record is <FONT color=3D#0080ff>QueryID =3D =
1</FONT>&nbsp;=20
and <FONT color=3D#0080ff>BooleanOperator =3D "And"</FONT>;&nbsp;Add=20
to&nbsp;database correctly;</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-=20
The value of the second record is <FONT color=3D#0080ff>QueryID =3D =
1</FONT> and=20
<FONT color=3D#0080ff>BooleanOperator =3D "Or"</FONT>; Add to database =
not=20
correctly;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Here is=20
the value in database:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
QueryID&nbsp;&nbsp;&nbsp; BooleanOperator</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
1&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
And</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nb=
sp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Or<FONT=20
color=3D#ff0000>d</FONT>&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The=20
value of BooleanOperator is "<FONT color=3D#ff0000>Ord</FONT>". Could =
you tell me=20
how to solve this problem, please?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Here is the =
code:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;OleDbCommand =
cmdClause =3D=20
new OleDbCommand();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
cmdClause.CommandType =3D=20
CommandType.StoredProcedure;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
cmdClause.CommandText =3D=20
SP_QUERY_SAVEQUERYCLAUSE;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
cmdClause.Parameters.Add(=20
"@QueryId", OleDbType.Integer);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
cmdClause.Parameters.Add(=20
"@BooleanOperator", OleDbType.VarWChar, 50);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; using =
(OleDbConnection cn =3D new=20
OleDbConnection(this.ConnectionString)) {</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;=20
cn.Open();</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmdClause.Connection=20
=3D=20
cn;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;=20
foreach (QueryClause clause in queryClauses)=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
cmdClause.Parameters["@QueryId"].Value =3D=20
queryId;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
cmdClause.Parameters["@BooleanOperator"].Value =3D=20
clause.BooleanOperator;</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
cmdClause.ExecuteNonQuery();</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;=20
}</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Hung</FONT></DIV></BODY></HTML>

------=_NextPart_000_0049_01C5052D.3F21E3E0--

Re: OleDbParameter doesn't update value correctly by ranjan

ranjan
Fri Jan 28 02:19:51 CST 2005

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


--


http://dotnetjunkies.com/weblog/dotnut

Re: OleDbParameter doesn't update value correctly by HungTrinh

HungTrinh
Sun Jan 30 20:09:33 CST 2005

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


<ranjan.listserv@gmail.com> wrote in message
news:%23p5yeIRBFHA.1564@TK2MSFTNGP09.phx.gbl...
> 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
>
>
> --
>
>
> http://dotnetjunkies.com/weblog/dotnut