If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Timestamp type mapping between Oledb and Odbc on .NET

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-29-03, 13:57
tawee80 tawee80 is offline
Registered User
 
Join Date: Oct 2003
Posts: 4
Timestamp type mapping between Oledb and Odbc on .NET

Hi,

I have a problem with .Net platform fetching data from DB2 on AS400 using DB2Connect OLEDB Provider, and iSeries Access ODBC driver. This is about getting my program to recognize the Timestamp data type returned from a query correctly. Using OLEDB all Date, Time and Timestamp are C#ystem.String. But with ODBC, they are correct.

Now, my real application crashes the aspnet_wp when I use ODBC driver. I open up the Event Viewer it reported something about COM+. So I have to use OLEDB, but it reports data type wrong.

Is there anyone who had this problem before? Do I need sort of DB2 fix packs or anything?

I wrote a little program to demonstrate my problem as followed:

sql: create table test3 (f1 date, f2 time, f3 timestamp)

C#:

// use DB2Connect OLEDB Provider
public static void testOleDbReader()
{
string cmd = "select * from test3";
string strConn = "Provider=IBMDA400;Data Source=xxx.xxx.xxx.xxx;User id=xxx;Password=xxx";
OleDbConnection cn = new OleDbConnection(strConn);
OleDbDataAdapter da;
DataSet ds = new DataSet();
cn.ConnectionString=strConn;
try {
da = new OleDbDataAdapter();
da.SelectCommand = new OleDbCommand(cmd);
da.SelectCommand.Connection = cn;
cn.Open();
da.Fill(ds);
OleDbDataReader myReader = da.SelectCommand.ExecuteReader();
foreach (DataColumn c in ds.Tables[0].Columns) {
Console.WriteLine(c.DataType);
}
} catch (Exception e) {
System.Console.WriteLine(e);
} finally {
cn.Close();
cn.Dispose();
}
}

result:
System.String
System.String
System.String

// use iSeries ODBC Driver with system dsn name 'xxx'
public static void testOdbcReader()
{
string cmd = "select * from test3";
string strConn = "DSN=xxx;UID=xxx;PWD=xxx;DBQ=xxx";
OdbcConnection cn = new OdbcConnection(strConn);
OdbcDataAdapter da;
DataSet ds = new DataSet();
cn.ConnectionString=strConn;
try {
da = new OdbcDataAdapter();
da.SelectCommand = new OdbcCommand(cmd);
da.SelectCommand.Connection = cn;
cn.Open();
da.Fill(ds);
OdbcDataReader myReader = da.SelectCommand.ExecuteReader();
foreach (DataColumn c in ds.Tables[0].Columns) {
Console.WriteLine(c.DataType);
}
} catch (Exception e) {
System.Console.WriteLine(e);
} finally {
cn.Close();
cn.Dispose();
}
}

result:
System.DateTime
System.TimeSpan
System.DateTime
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On