By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,813 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,813 IT Pros & Developers. It's quick & easy.

.net and system.data.oracleclient datetime question

P: n/a
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.oracleclient

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OracleClient;
using System.Data;

OracleConnection oOracleConn = new OracleConnection(conn);
oOracleConn.Open();
OracleCommand cmd = oOracleConn.CreateCommand();
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
OracleDataAdapter adapt = new OracleDataAdapter(cmd);
DataSet myDataSet = new DataSet();
myDataSet.Clear();
adapt.Fill(myDataSet);

Jun 27 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a

<vb********@yahoo.comwrote in message
news:6e**********************************@w7g2000h sa.googlegroups.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.oracleclient

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OracleClient;
using System.Data;

OracleConnection oOracleConn = new OracleConnection(conn);
oOracleConn.Open();
OracleCommand cmd = oOracleConn.CreateCommand();
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
OracleDataAdapter adapt = new OracleDataAdapter(cmd);
DataSet myDataSet = new DataSet();
myDataSet.Clear();
adapt.Fill(myDataSet);
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("mmddyyyy"), 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.


Jun 27 '08 #2

P: n/a
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("mmddyyyy");
ERROR: No overload for method ToString takes 1 arguments

ArrayList arr = new ArrayList(dr.ItemArray);
datetime = arr.ToString("mmddyyyy");
ERROR: No overload for method ToString takes 1 arguments

datetime = dr.ItemArray[j].ToString().Replace("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.
Jun 27 '08 #3

P: n/a
sorry I forgot to mention - stored procs are not an option
Jun 27 '08 #4

P: n/a

<vb********@yahoo.comwrote in message
news:cd**********************************@59g2000h sb.googlegroups.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("mmddyyyy");
ERROR: No overload for method ToString takes 1 arguments

ArrayList arr = new ArrayList(dr.ItemArray);
datetime = arr.ToString("mmddyyyy");
ERROR: No overload for method ToString takes 1 arguments

datetime = dr.ItemArray[j].ToString().Replace("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>

Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.