.net and system.data.oracleclient datetime question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vbcsdotnet@yahoo.com

    .net and system.data.oracleclient datetime question

    hello I run an sql which returns a datarow itemarray field of
    system.datetime . the problem is the database
    only stores the date, but the returned value includes a time of
    12:00:00 AM. I do not want the time.
    How can I get only the date returned, just as it is stored in the
    database? thanks

    reference - system.data.ora cleclient

    using System;
    using System.Collecti ons.Generic;
    using System.Text;
    using System.Data.Ora cleClient;
    using System.Data;

    OracleConnectio n oOracleConn = new OracleConnectio n(conn);
    oOracleConn.Ope n();
    OracleCommand cmd = oOracleConn.Cre ateCommand();
    cmd.CommandText = sql;
    cmd.CommandType = CommandType.Tex t;
    OracleDataAdapt er adapt = new OracleDataAdapt er(cmd);
    DataSet myDataSet = new DataSet();
    myDataSet.Clear ();
    adapt.Fill(myDa taSet);





  • Mr. Arnold

    #2
    Re: .net and system.data.ora cleclient datetime question


    <vbcsdotnet@yah oo.comwrote in message
    news:6ed51815-c819-45c9-a5ce-994feab21edb@w7 g2000hsa.google groups.com...
    hello I run an sql which returns a datarow itemarray field of
    system.datetime . the problem is the database
    only stores the date, but the returned value includes a time of
    12:00:00 AM. I do not want the time.
    How can I get only the date returned, just as it is stored in the
    database? thanks
    >
    reference - system.data.ora cleclient
    >
    using System;
    using System.Collecti ons.Generic;
    using System.Text;
    using System.Data.Ora cleClient;
    using System.Data;
    >
    OracleConnectio n oOracleConn = new OracleConnectio n(conn);
    oOracleConn.Ope n();
    OracleCommand cmd = oOracleConn.Cre ateCommand();
    cmd.CommandText = sql;
    cmd.CommandType = CommandType.Tex t;
    OracleDataAdapt er adapt = new OracleDataAdapt er(cmd);
    DataSet myDataSet = new DataSet();
    myDataSet.Clear ();
    adapt.Fill(myDa taSet);
    >
    You would have to use a stored proc on Oracle that would String Format the
    date with a mask of ("mmddyyyy") , as and example, the way you wanted it
    when it returned the result set. A stored proc in Oracle is the equivalent
    to a stored procedure on MS SQL Server.

    The other way you could do it is make a Accessor Object (AO) that represents
    the fields of the dataset table fields in question and walk the table row
    by row. On each row read, you populate corresponding fields to the AO.
    However for the date field, you would use a ToString on the date field in
    the table to populate the string date field in the AO. The ToString would
    look like this -- ToString("mmddy yyy"), and then you add the AO to an
    ArrayList which can be bound to a datasource of a DataGridView as an
    example.

    Or you could use the List <another form of an ArrayList.




    Comment

    • vbcsdotnet@yahoo.com

      #3
      Re: .net and system.data.ora cleclient datetime question

      Thanks Mr Arnold,

      I have tried to do what you describe with the AO, probably I do not
      really understand what you are saying.
      The ToString method does not seem to take any arguments.

      string datetime;

      datetime = dr.ItemArray[j].ToString("mmdd yyyy");
      ERROR: No overload for method ToString takes 1 arguments

      ArrayList arr = new ArrayList(dr.It emArray);
      datetime = arr.ToString("m mddyyyy");
      ERROR: No overload for method ToString takes 1 arguments

      datetime = dr.ItemArray[j].ToString().Rep lace("12:00:00 AM", "");
      WORKS - maybe there is a more efficient way than this

      ideally, the sql could send it back "correctly" - to_char, trunc have
      no effect.

      Comment

      • vbcsdotnet@yahoo.com

        #4
        Re: .net and system.data.ora cleclient datetime question

        sorry I forgot to mention - stored procs are not an option

        Comment

        • Mr. Arnold

          #5
          Re: .net and system.data.ora cleclient datetime question


          <vbcsdotnet@yah oo.comwrote in message
          news:cd27780c-989f-42bb-931c-65949fa318f7@59 g2000hsb.google groups.com...
          Thanks Mr Arnold,
          >
          I have tried to do what you describe with the AO, probably I do not
          really understand what you are saying.
          The ToString method does not seem to take any arguments.
          >
          string datetime;
          >
          datetime = dr.ItemArray[j].ToString("mmdd yyyy");
          ERROR: No overload for method ToString takes 1 arguments
          >
          ArrayList arr = new ArrayList(dr.It emArray);
          datetime = arr.ToString("m mddyyyy");
          ERROR: No overload for method ToString takes 1 arguments
          >
          datetime = dr.ItemArray[j].ToString().Rep lace("12:00:00 AM", "");
          WORKS - maybe there is a more efficient way than this
          >
          ideally, the sql could send it back "correctly" - to_char, trunc have
          no effect.

          Yes, you can use the ToString("with mask"). I just couldn't remember the
          correct mask type you should use.

          <http://blogs.msdn.com/kathykam/archive/2006/09/29/.NET-Format-String-102_3A00_-DateTime-Format-String.aspx>

          Comment

          Working...