Passing DateTime to sp via OleDbDataAdapter

T

thorax

[Originally posted in Sybase newsgroups but received no response.]

I'm having trouble passing a .NET DateTime value to a stored procedure
(parameter type datetime). Regardless of how the value is specified, it
seems to get truncated so the stored procedure receives the wrong value.
Below is the code which creates the columns on the untyped dataset,
where the values are being set and finally the values that finally make
it to ASA. (I'm running SA 9.02 + EBF 3302 on XP SP2.

Can anyone point me to what I'm doing wrong? Thanks in advance for any
help.

Steve.


1) Columns are added to untyped dataset:
pCol = pTable->Columns->Add(S"created_date", __typeof
(System::DateTime));
pCol = pTable->Columns->Add(S"modified_date", __typeof
(System::DateTime));

2) Sample code setting values for fields:
CTime ctNow(2006, 10, 26, 11, 12, 13);
DateTime dtNow(2006, 10, 26, 11, 12, 13);
s = ctNow.Format("%Y-%m-%d %H:%M:%S");
pRow->Item[S"created_date"] = s;
pRow->Item[S"modified_date"] = __box(dtNow);

3) Values as seen in debugger
s = 2006-10-26 11:12:13
__box(dtNow) = 26/10/2006 11:12:13

4) Code updating database:
bRetVal = m_pDatasetsAdapter->Update(pTable);

Value as displayed in ASA SQL log (-zr all):
10/26 10:22:01.810 ** HOSTVAR conn: 4 5 varchar '2006-10-'
<---- VALUE IS TRUNCATED
10/26 10:22:01.810 ** HOSTVAR conn: 4 6 varchar '2006-10-'
<---- VALUE IS TRUNCATED
 
W

WenYuan Wang

Hi Steve

First of all, I'd like to confirm my understanding of this issue.
According to your description, you have some trouble passing a .NET
DateTime value to a stored procedure.
If I misunderstood anything here, please don't hesitate to correct me.
You can try below ways to narrow down the issue.

1.> pCol = pTable->Columns->Add(S"created_date",
__typeof(System::DateTime));
Have you considered using System.Data.DbType.DateTime?
(e.g: pTable.Columns.Add("created_date",System.Data.DbType.DateTime))
We should use System.Data.DbType.DateTime rather than System.DateTime.

2. using typed dateset, you can get more performance.

3. using SQL Query command to check if it is a problem related to the store
procedure.

Hope this helps,
If you have anything unclear,
please feel free to post in the newsgroup and we will follow up.
Wen Yuan
===============================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
===============================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top