473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

.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.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
4 2523

<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
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
sorry I forgot to mention - stored procs are not an option
Jun 27 '08 #4

<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kevin Vogt | last post by:
When initially loaded, my web application (below) takes ~120000 milliseconds to open its connection. But repeated executions take 0 milliseconds each. But when I wait for approx. 5 minutes and try...
4
by: ben | last post by:
Below is the error message I am receiving on a production server with the Oracle 9.2 client installed. However, on a Oracle 9.0 client installation on the development server the problem does not...
2
by: JJ | last post by:
Hi, I don't know if this is the correct newsgroup to post this question, but here goes. I have installed Visual Studio .Net Professional 2003. I checked the version and it is 7.1.3088. It...
0
by: George | last post by:
I have an aspx page, this page instance a Dll make for me, this Dll imports System.Data.OracleClient, I Add the Reference in the project and use the gcautil -i but the error "Namespace or type...
10
by: Paul Deibel | last post by:
Hello I am working on a VB.Net project where I need to change the data provider from OLEDB to OracleClient. I am also looking to use "shaping" and I am looking for the equivalent to...
0
by: =?Utf-8?B?U2FyYWggVw==?= | last post by:
Hello, How can I read data field from an oracle procedure with 'long-raw' data type , using oracle client data adapter? I tried that: objPic = New clsPersInfoDT vCParam1 = New...
4
by: Peter Kanurer | last post by:
Assume I add in VisualCSharp 2005 References to Oracle.DataAccess AND System.Data.OracleClient to an application. Does this cause problems or can they co-exist in one application ?
3
by: sriram347 | last post by:
Hi I am a newbie to ASP.NET. I developed a web page (project type is web application) and I keep getting this error. B]Error message : "System.AccessViolation Exception attempted to read or...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.