[Mono-list] Re: Mono DataAdapter problem?
Agus Surachman
agus.surachman@ppatk.go.id
Tue, 27 Jul 2004 11:56:57 +0700
This is a multi-part message in MIME format.
------=_NextPart_000_0055_01C473D0.D10C1BC0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Dear all,
Is there something weird with Mono Data Adapter?
My script code as attached below give different result if I run using =
.NET and Mono.
Seems that there is a problem when filling DataTable with DataAdapter.
Please your help.
-Aguss
private static string p_GetNextSequence(string szPjkCode, string =
szFtrTypeCode, DateTime dtmExtraction)
{
OraDatabase db =3D new OraDatabase();
string _debug =3D ""; //tambahan aguss
=20
try
{
_debug =3D "opening..;"; //tamabahn aguss
db.Open();
_debug +=3D "beginning...;"; //tambahan aguss
db.Begin();
=20
_debug +=3D "getting text command...;"; //tambahan aguss
OracleCommand cmd =3D db.GetTextCommand();
=20
// Check if the counter is already exist in the table.
// Before getting the row, lock it first so that no one can modify =
it when we work on it.
=20
// Lock (by updating SEQ_NUMBER =3D SEQ_NUMBER + 1).
//
_debug +=3D "executing updating sequence command...;"; //tambahan =
aguss
cmd.CommandText =3D "UPDATE UPLOADER_SEQUENCE SET" + " SEQ_NUMBER =
=3D SEQ_NUMBER + 1" + " WHERE" + " LOWER(PJK_CODE) =3D '" + =
szPjkCode.ToLower() + "'" + " AND FTR_DATE =3D " + =
DtmDateToOraDateString(dtmExtraction) + " AND LOWER(FTR_TYPE_CODE) =3D =
'" + szFtrTypeCode.ToLower() + "'";
=20
_debug +=3D cmd.CommandText + "...;";=20
cmd.ExecuteNonQuery();
=20
// Read the row to check if the counter is already exist in the =
table.
//
cmd.CommandText =3D "SELECT SEQ_NUMBER" + " FROM UPLOADER_SEQUENCE" =
+ " WHERE" + " LOWER(PJK_CODE) =3D '" + szPjkCode.ToLower() + "'" + " =
AND FTR_DATE =3D " + DtmDateToOraDateString(dtmExtraction) + " AND =
LOWER(FTR_TYPE_CODE) =3D '" + szFtrTypeCode.ToLower() + "'";
=20
_debug +=3D "creating data adapater...;";=20
=20
=20
_debug +=3D cmd.CommandText + "...;";=20
=20
OracleDataAdapter da =3D new OracleDataAdapter(cmd);
DataTable dt =3D new DataTable();
_debug +=3D "filling data adapter...;";
da.Fill(dt);
=20
int iNextSeqNo;
=20
_debug +=3D"nilai Rows dari data adapter: " + dt.Rows.Count + =
"...;";
=20
if (dt.Rows.Count =3D=3D 0)
{
// If counter not found, create (also set the SEQ_NUMBER =3D 1).
cmd.CommandText =3D "INSERT INTO UPLOADER_SEQUENCE (" + " =
PJK_CODE," + " FTR_DATE," + " FTR_TYPE_CODE," + " SEQ_NUMBER" + " ) =
VALUES (" + " '" + szPjkCode + "'," + " " + =
DtmDateToOraDateString(dtmExtraction) + "," + " '" + szFtrTypeCode + =
"'," + " 1" + " )";
=20
_debug +=3D "inserting into uploader sequence:..." + =
cmd.CommandText + "....;";
=20
cmd.ExecuteNonQuery();
=20
iNextSeqNo =3D 1;
=20
}
else
{
// If found, return the counter.
// No need to check if SEQ_NUMBER is null or not (it must not be =
null!).
iNextSeqNo =3D System.Convert.ToInt32(dt.Rows[0]["SEQ_NUMBER"]);
=20
} // dt.Rows.Count.
=20
db.Commit();
=20
//return iNextSeqNo;
return "next sequence: " + iNextSeqNo.ToString() + "; " + _debug;
=20
}
catch(Exception exp){ //tambahan aguss
return ("Error get sequence: " + _debug + " " + exp.Message); =
//tambahan aguss
} //tambahan aguss
finally
{
db.Close();
}
}
Output from .NET:
opening..;beginning...;getting text command...;executing updating =
sequence command...;UPDATE UPLOADER_SEQUENCE SET SEQ_NUMBER =3D =
SEQ_NUMBER + 1 WHERE LOWER(PJK_CODE) =3D 'ppatk' AND FTR_DATE =3D =
TO_DATE('27-7-2004', 'DD-MM-YYYY') AND LOWER(FTR_TYPE_CODE) =3D =
'c'...;creating data adapater...;SELECT SEQ_NUMBER FROM =
UPLOADER_SEQUENCE WHERE LOWER(PJK_CODE) =3D 'ppatk' AND FTR_DATE =3D =
TO_DATE('27-7-2004', 'DD-MM-YYYY') AND LOWER(FTR_TYPE_CODE) =3D =
'c'...;filling data adapter...;nilai Rows dari data adapter: 1...;
Output from Mono
opening..;beginning...;getting text command...;executing updating =
sequence command...;UPDATE UPLOADER_SEQUENCE SET SEQ_NUMBER =3D =
SEQ_NUMBER + 1 WHERE LOWER(PJK_CODE) =3D 'ppatk' AND FTR_DATE =3D =
TO_DATE('27-7-2004', 'DD-MM-YYYY') AND LOWER(FTR_TYPE_CODE) =3D =
'c'...;creating data adapater...;SELECT SEQ_NUMBER FROM =
UPLOADER_SEQUENCE WHERE LOWER(PJK_CODE) =3D 'ppatk' AND FTR_DATE =3D =
TO_DATE('27-7-2004', 'DD-MM-YYYY') AND LOWER(FTR_TYPE_CODE) =3D =
'c'...;filling data adapter...;nilai Rows dari data adapter: 0...;
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.726 / Virus Database: 481 - Release Date: 7/22/2004
------=_NextPart_000_0055_01C473D0.D10C1BC0
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.1400" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Dear all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Is there something weird with Mono Data =
Adapter?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>My script code as attached below give =
different=20
result if I run using .NET and Mono.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Seems that there is a problem when =
filling=20
DataTable with DataAdapter.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Please your help.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>-Aguss</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>private static string =
p_GetNextSequence(string szPjkCode, string szFtrTypeCode, DateTime=20
dtmExtraction)<BR> {<BR> OraDatabase db =3D =
new=20
OraDatabase();<BR> string _debug =3D=20
""; //tambahan=20
aguss<BR> <BR> try<BR>  =
;{<BR> _debug=20
=3D "opening..;"; //tamabahn=20
aguss<BR> db.Open();<BR> _d=
ebug +=3D=20
"beginning...;"; //tambahan=20
aguss<BR> db.Begin();<BR> <=
BR> _debug=20
+=3D "getting text command...;"; //tambahan aguss</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080=20
size=3D2> OracleCommand cmd =3D=20
db.GetTextCommand();<BR> <BR> &nb=
sp;//=20
Check if the counter is already exist in the=20
table.<BR> // Before getting the row, lock it =
first so=20
that no one can modify it when we work on=20
it.<BR> <BR> // Lock (by =
updating=20
SEQ_NUMBER =3D SEQ_NUMBER + =
1).<BR> //</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 =
size=3D2> _debug +=3D=20
"executing updating sequence command...;"; //tambahan =
aguss</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080=20
size=3D2> cmd.CommandText =3D "UPDATE =
UPLOADER_SEQUENCE SET"=20
+ " SEQ_NUMBER =3D SEQ_NUMBER + 1" + " WHERE" + " LOWER(PJK_CODE) =3D '" =
+=20
szPjkCode.ToLower() + "'" + " AND FTR_DATE =3D " +=20
DtmDateToOraDateString(dtmExtraction) + " AND LOWER(FTR_TYPE_CODE) =3D =
'" +=20
szFtrTypeCode.ToLower() +=20
"'";<BR> <BR> _debug +=3D=20
cmd.CommandText + "...;"; </FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080=20
size=3D2> cmd.ExecuteNonQuery();<BR> &n=
bsp; <BR> //=20
Read the row to check if the counter is already exist in the=20
table.<BR> //<BR> cmd.Comma=
ndText=20
=3D "SELECT SEQ_NUMBER" + " FROM UPLOADER_SEQUENCE" + " WHERE" + " =
LOWER(PJK_CODE)=20
=3D '" + szPjkCode.ToLower() + "'" + " AND FTR_DATE =3D " +=20
DtmDateToOraDateString(dtmExtraction) + " AND LOWER(FTR_TYPE_CODE) =3D =
'" +=20
szFtrTypeCode.ToLower() + "'";<BR> </FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 =
size=3D2> _debug +=3D=20
"creating data=20
adapater...;"; <BR> <BR> <BR=
> _debug=20
+=3D cmd.CommandText + =
"...;"; <BR> <BR><STRONG><FONT=20
color=3D#800000 size=3D3> OracleDataAdapter da =
=3D new=20
OracleDataAdapter(cmd);<BR> DataTable dt =3D new=20
DataTable();</FONT></STRONG></FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 =
size=3D2> _debug +=3D=20
"filling data adapter...;";</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2> <FONT =
color=3D#800000=20
size=3D3><STRONG> da.Fill(dt);</STRONG></FONT><BR> =
<BR> int=20
iNextSeqNo;<BR> <BR> _debug =
+=3D"nilai=20
Rows dari data adapter: " + dt.Rows.Count +=20
"...;";<BR> <BR> if=20
(dt.Rows.Count =3D=3D 0)<BR> {</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 =
size=3D2> // If=20
counter not found, create (also set the SEQ_NUMBER =3D=20
1).<BR> cmd.CommandText =3D "INSERT INTO=20
UPLOADER_SEQUENCE (" + " PJK_CODE," + " FTR_DATE," + " FTR_TYPE_CODE," + =
"=20
SEQ_NUMBER" + " ) VALUES (" + " '" + szPjkCode + "'," + " " +=20
DtmDateToOraDateString(dtmExtraction) + "," + " '" + szFtrTypeCode + =
"'," + " 1"=20
+ " )";<BR> </FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080=20
size=3D2><BR> _debug +=3D "inserting into =
uploader=20
sequence:..." + cmd.CommandText +=20
"....;";<BR> <BR> &nb=
sp;cmd.ExecuteNonQuery();<BR> <BR> &nbs=
p; iNextSeqNo=20
=3D=20
1;<BR> <BR> }<BR>&nbs=
p; else<BR> {<BR> &nbs=
p; //=20
If found, return the counter.<BR> // No =
need to=20
check if SEQ_NUMBER is null or not (it must not be=20
null!).<BR> iNextSeqNo =3D=20
System.Convert.ToInt32(dt.Rows[0]["SEQ_NUMBER"]);<BR> &n=
bsp; <BR> }=20
//=20
dt.Rows.Count.<BR> <BR> db.=
Commit();<BR> <BR> //return=
=20
iNextSeqNo;<BR> return "next sequence: " +=20
iNextSeqNo.ToString() + "; " +=20
_debug;<BR> <BR> }<BR>  =
; catch(Exception=20
exp){ //tambahan=20
aguss<BR> return ("Error get sequence: " + _debug =
+ " " +=20
exp.Message); //tambahan=20
aguss<BR> } //t=
ambahan=20
aguss<BR> finally<BR> {<BR> =
db.Close();<BR> }<BR> }</FONT></D=
IV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><STRONG>Output from =
.NET:</STRONG></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier size=3D2>opening..;beginning...;getting text=20
command...;executing updating sequence command...;UPDATE =
UPLOADER_SEQUENCE SET=20
SEQ_NUMBER =3D SEQ_NUMBER + 1 WHERE LOWER(PJK_CODE) =3D 'ppatk' AND =
FTR_DATE =3D=20
TO_DATE('27-7-2004', 'DD-MM-YYYY') AND LOWER(FTR_TYPE_CODE) =3D =
'c'...;creating=20
data adapater...;SELECT SEQ_NUMBER FROM UPLOADER_SEQUENCE WHERE =
LOWER(PJK_CODE)=20
=3D 'ppatk' AND FTR_DATE =3D TO_DATE('27-7-2004', 'DD-MM-YYYY') AND=20
LOWER(FTR_TYPE_CODE) =3D 'c'...;filling data adapter...;nilai =
<STRONG><FONT=20
color=3D#800000 size=3D3>Rows dari data adapter: =
1...;</FONT></STRONG></FONT></DIV>
<DIV><FONT face=3DCourier size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><STRONG>Output from =
Mono</STRONG></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier size=3D2>opening..;beginning...;getting text=20
command...;executing updating sequence command...;UPDATE =
UPLOADER_SEQUENCE SET=20
SEQ_NUMBER =3D SEQ_NUMBER + 1 WHERE LOWER(PJK_CODE) =3D 'ppatk' AND =
FTR_DATE =3D=20
TO_DATE('27-7-2004', 'DD-MM-YYYY') AND LOWER(FTR_TYPE_CODE) =3D =
'c'...;creating=20
data adapater...;SELECT SEQ_NUMBER FROM UPLOADER_SEQUENCE WHERE =
LOWER(PJK_CODE)=20
=3D 'ppatk' AND FTR_DATE =3D TO_DATE('27-7-2004', 'DD-MM-YYYY') AND=20
LOWER(FTR_TYPE_CODE) =3D 'c'...;filling data adapter...;nilai =
<STRONG><FONT=20
color=3D#800000 size=3D3>Rows dari data adapter: =
0...;</FONT></STRONG></FONT></DIV>
<DIV> </DIV>
<BLOCKQUOTE>
<DIV> </DIV>
<DIV> </DIV>
<DIV><BR>---<BR>Outgoing mail is certified Virus Free.<BR>Checked by =
AVG=20
anti-virus system (<A=20
=
href=3D"http://www.grisoft.com">http://www.grisoft.com</A>).<BR>Version: =
6.0.726=20
/ Virus Database: 481 - Release Date: =
7/22/2004</DIV></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_0055_01C473D0.D10C1BC0--