Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 28th, 2005, 04:29 AM
spc spc is offline
Registered User
 
Join Date: Nov 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Unable to read Time field value from MySQL DB

Hi All,

  I have developed a Migration Tool that migrates data from MySQL to MSSQL. But I am finding a problem to read the time field value from MySQL database . I was using DataSet(.Net framework) for my application to retrieve the records from database & storing them into that. Although the values are there in MySQL DB , the value I got while reading was System.DBNull.Value .
   Please help me as soon as possible. Is it because of the driver I am using?? I have used MySQL-ODBC Bridge Version 3.51 for my application.

  Thanks.
Shubhabrata



 
Old November 28th, 2005, 02:25 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

What is your select statement? Did you run the query in QA to check that you are getting the proper values you expect from the query?

 
Old November 29th, 2005, 09:28 AM
spc spc is offline
Registered User
 
Join Date: Nov 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi benson,
Thanks for ur prompt reply. Yes , I have executed the query "select * from jobschedules" in the MySQL Query Browser. It is working fine there.But the problem occurs when I executed the following code -

static void Main(string[] args)
{
    OdbcConnection oConn =new OdbcConnection("DRIVER={MySQL ODBC 3.51 Driver};SERVER=delta;Database=afndbpdev;Uid=afndbp dev;Pwd=afndbpdev;");
    OdbcCommand oComm=new OdbcCommand();

    String tabname=String.Empty;
    oConn.Open();
    oComm.Connection=oConn;
    DataSet ds =new DataSet();

    oComm.CommandText="select * from jobschedule";
    OdbcDataAdapter oDA=new OdbcDataAdapter(oComm);
    // OdbcDataReader dr=null;
    try
    {
         oDA.FillSchema(ds,System.Data.SchemaType.Source) ;
         oDA.Fill(ds);
         // dr= oComm.ExecuteReader();
    }
    catch(Exception err)
    {
         Console.WriteLine(err.Message);
    }
        /*int i=0;
    while(dr.Read())
    {
    if(i>=dr.FieldCount)i=0;
    Console.WriteLine(dr.GetDataTypeName(i)+" "+dr.GetValue(i).ToString());

        i++;
    }*/
    foreach(DataRow r in ds.Tables[0].Rows)
     foreach(DataColumn c in ds.Tables[0].Columns )
     {
        Console.Write(c.DataType.ToString()+" ");
        Console.WriteLine(r[c].ToString());
        if(c.DataType.ToString().Equals("System.TimeSpan") )
        {
             Console.Write(" Value: "+ r[c].ToString());
         if(r[c]==System.DBNull.Value)
         Console.WriteLine("The Value is null");

        }
        }
}

    I am getting the values for all other fields from the code except the time field(i.e. scheduletime) . Here is the schema details for the table 'jobschedule' -

CREATE TABLE jobschedule
(
jobid int(11) default NULL,
assnnbr int(11) default NULL,
emails text,
jobtype varchar(255) default NULL,
jobdescription varchar(255) default NULL,
jobarguments varchar(255) default NULL,
lastuserbatched datetime default NULL,
lastautobatched datetime default NULL,
scheduletype char(1) default NULL,
scheduledate tinyint(4) default NULL,
scheduletime time default NULL,
enabled char(1) default NULL
)

Pls help me fast as I am running out of time.
The output is as follows -
System.Int32 1
System.Int32 295
System.String [email protected]
System.String DownloadMembership
System.String Daily Nightly Downlad
System.String
System.DateTime 2/8/2005 2:28:31 PM
System.DateTime 10/24/2005 11:06:37 PM
System.String D
System.Int16 1
System.TimeSpan
Value: The value is Null
System.String Y
 
Old November 29th, 2005, 11:34 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You are trying to write the value of the time col, then you are checking it for null, then writing it again??
Why????


    Console.Write(" Value: "+ r[c].ToString());
           if(r[c]==System.DBNull.Value)
           Console.WriteLine(r[c].ToString());


I am not familiar with MYSQL. But you need to:
First Check if the type is a "time"
Then check if it is NULL,
If it isn't NULL write the value,
If it is NULL, write a message "The value is NULL"


Jim

 
Old November 30th, 2005, 01:15 AM
spc spc is offline
Registered User
 
Join Date: Nov 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jim,
I was just trying to be very sure that the datatype 'System.TimeSpan' is equivalent to 'Time' in database. That's why I was printing it twice. But Now I have changed thecode for Null value & I am printing -"The Value is Null".

Please check my earlier message, where I have displayed the output of the code.Please have a look on that . The content in the database was something like this (in the same order of the columns as discussed while creating the table)-
1, 295, '[email protected]', 'DownloadMembership', 'Daily Nightly Downlad', '', '2005-02-08 14:28:31', '2005-10-24 23:06:37', 'D', 1, 23:00:00, 'Y'.

Hope it will help you to figure out the problem.
Bye
Spc





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to read Time field value from MySQL DB spc C# 3 August 6th, 2007 01:33 PM
unable to connect PHP with Mysql bhavna MySQL 1 June 5th, 2007 07:52 PM
Unable to open ProjectTimeTracker DB cancer2006 BOOK: Beginning VB.NET Databases 2 October 24th, 2006 03:53 PM
Unable to import db The Beginner SQL Server 2000 9 August 24th, 2006 06:03 AM
Unable to INSERT INTO db nvillare Classic ASP Databases 6 August 26th, 2003 10:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.