[Mono-list] Mono DataAdapter problem?

Agus Surachman agus.surachman@ppatk.go.id
Tue, 27 Jul 2004 11:57:27 +0700


This is a multi-part message in MIME format.


------=_NextPart_000_0062_01C473D0.E2E46FF0
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_0062_01C473D0.E2E46FF0
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></FONT>&nbsp;</DIV>
<DIV><BR></DIV>
<DIV><FONT face=3DArial size=3D2>Dear all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Is there something weird with Mono Data =

Adapter?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>-Aguss</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>private static string =

p_GetNextSequence(string szPjkCode, string szFtrTypeCode, DateTime=20
dtmExtraction)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;OraDatabase db =3D =
new=20
OraDatabase();<BR>&nbsp;&nbsp;&nbsp;string _debug =3D=20
"";&nbsp;&nbsp;&nbsp;//tambahan=20
aguss<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp=
;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;_debug=20
=3D "opening..;";&nbsp;&nbsp;//tamabahn=20
aguss<BR>&nbsp;&nbsp;&nbsp;&nbsp;db.Open();<BR>&nbsp;&nbsp;&nbsp;&nbsp;_d=
ebug +=3D=20
"beginning...;";&nbsp;//tambahan=20
aguss<BR>&nbsp;&nbsp;&nbsp;&nbsp;db.Begin();<BR>&nbsp;&nbsp;&nbsp;&nbsp;<=
BR>&nbsp;&nbsp;&nbsp;&nbsp;_debug=20
+=3D "getting text command...;";&nbsp;//tambahan aguss</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCourier color=3D#000080=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;OracleCommand cmd =3D=20
db.GetTextCommand();<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nb=
sp;//=20
Check if the counter is already exist in the=20
table.<BR>&nbsp;&nbsp;&nbsp;&nbsp;// Before getting the row, lock it =
first so=20
that no one can modify it when we work on=20
it.<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;// Lock (by =
updating=20
SEQ_NUMBER =3D SEQ_NUMBER + =
1).<BR>&nbsp;&nbsp;&nbsp;&nbsp;//</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCourier color=3D#000080 =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;_debug +=3D=20
"executing updating sequence command...;";&nbsp;//tambahan =
aguss</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCourier color=3D#000080=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;_debug +=3D=20
cmd.CommandText + "...;";&nbsp;</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCourier color=3D#000080=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;cmd.ExecuteNonQuery();<BR>&nbsp;&nbsp;&n=
bsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//=20
Read the row to check if the counter is already exist in the=20
table.<BR>&nbsp;&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCourier color=3D#000080 =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;_debug +=3D=20
"creating data=20
adapater...;";&nbsp;<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR=
>&nbsp;&nbsp;&nbsp;&nbsp;_debug=20
+=3D cmd.CommandText + =
"...;";&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR><STRONG><FONT=20
color=3D#800000 size=3D3>&nbsp;&nbsp;&nbsp;&nbsp;OracleDataAdapter da =
=3D new=20
OracleDataAdapter(cmd);<BR>&nbsp;&nbsp;&nbsp;&nbsp;DataTable dt =3D new=20
DataTable();</FONT></STRONG></FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCourier color=3D#000080 =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;_debug +=3D=20
"filling data adapter...;";</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>&nbsp;<FONT =
color=3D#800000=20
size=3D3><STRONG>&nbsp;&nbsp;&nbsp;da.Fill(dt);</STRONG></FONT><BR>&nbsp;=
&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;int=20
iNextSeqNo;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;_debug =
+=3D"nilai=20
Rows dari data adapter: " + dt.Rows.Count +=20
"...;";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;if=20
(dt.Rows.Count =3D=3D 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCourier color=3D#000080 =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// If=20
counter not found, create (also set the SEQ_NUMBER =3D=20
1).<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCourier color=3D#000080=20
size=3D2><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_debug +=3D "inserting into =
uploader=20
sequence:..." + cmd.CommandText +=20
"....;";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;cmd.ExecuteNonQuery();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;iNextSeqNo=20
=3D=20
1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbs=
p;&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;//=20
If found, return the counter.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// No =
need to=20
check if SEQ_NUMBER is null or not (it must not be=20
null!).<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iNextSeqNo =3D=20
System.Convert.ToInt32(dt.Rows[0]["SEQ_NUMBER"]);<BR>&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}=20
//=20
dt.Rows.Count.<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;db.=
Commit();<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//return=
=20
iNextSeqNo;<BR>&nbsp;&nbsp;&nbsp;&nbsp;return "next sequence: " +=20
iNextSeqNo.ToString() + "; " +=20
_debug;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp=
;&nbsp;catch(Exception=20
exp){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//tambahan=20
aguss<BR>&nbsp;&nbsp;&nbsp;&nbsp;return ("Error get sequence: " + _debug =
+ " " +=20
exp.Message);&nbsp;//tambahan=20
aguss<BR>&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//t=
ambahan=20
aguss<BR>&nbsp;&nbsp;&nbsp;finally<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;=
&nbsp;&nbsp;db.Close();<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}</FONT></D=
IV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><STRONG>Output from =
.NET:</STRONG></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><STRONG>Output from =
Mono</STRONG></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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>&nbsp;</DIV>
<BLOCKQUOTE>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp;</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_0062_01C473D0.E2E46FF0--