Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DBAdapter.Fill(), datatype matching.

DBAdapter.Fill(), datatype matching.

Scheduled Pinned Locked Moved C#
databasemysqlhelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zecodela
    wrote on last edited by
    #1

    i stored a Time field in MySQL database and the DBAdapter.Fill() use DateTime to store the return value. and, this leads to 'FormatException'. do u know any method to do some custom datatype matching to solve this problem? or, i just go to change the datatype in database to string or other simply datatype? thanks, jim

    S H 2 Replies Last reply
    0
    • Z zecodela

      i stored a Time field in MySQL database and the DBAdapter.Fill() use DateTime to store the return value. and, this leads to 'FormatException'. do u know any method to do some custom datatype matching to solve this problem? or, i just go to change the datatype in database to string or other simply datatype? thanks, jim

      S Offline
      S Offline
      sreejith ss nair
      wrote on last edited by
      #2

      Try to use ToString() method before passing into the database. Eg: DateTime dt; Assume that, dt is 12-12-2004 12:24:44 Am; dt.ToString("yyyy-MMM-dd") will return 2004-Dec-12. dt.ToString("yyyy/MMM/dd") will return 2004/Dec/12. dt.ToString("yyyy-MM-dd") will return 2004-12-12. dt.ToString("yyyy/MM/dd") will return 2004/12/12. dt.ToString("mm-DD-yyyy") will return 12-12-2004. dt.ToString("mm/DD/yyyy") will return 12/12/2004. Hope this will serve your purpose. Sreejith Nair [ My Articles ]

      H 1 Reply Last reply
      0
      • S sreejith ss nair

        Try to use ToString() method before passing into the database. Eg: DateTime dt; Assume that, dt is 12-12-2004 12:24:44 Am; dt.ToString("yyyy-MMM-dd") will return 2004-Dec-12. dt.ToString("yyyy/MMM/dd") will return 2004/Dec/12. dt.ToString("yyyy-MM-dd") will return 2004-12-12. dt.ToString("yyyy/MM/dd") will return 2004/12/12. dt.ToString("mm-DD-yyyy") will return 12-12-2004. dt.ToString("mm/DD/yyyy") will return 12/12/2004. Hope this will serve your purpose. Sreejith Nair [ My Articles ]

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        He's trying to fill a DataSet, not update the database. Besides, if you specify SqlDbType.DateTime for the column type then the value should be an instance of the DateTime struct. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

        1 Reply Last reply
        0
        • Z zecodela

          i stored a Time field in MySQL database and the DBAdapter.Fill() use DateTime to store the return value. and, this leads to 'FormatException'. do u know any method to do some custom datatype matching to solve this problem? or, i just go to change the datatype in database to string or other simply datatype? thanks, jim

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          There is no time type in SQL Server. If you're referring to the timestamp type then be sure to read the documentation for the SqlDbType enumeration. A timestamp translates to a byte[] array. In SQL Server a timestamp is an automatically generated array of binary numbers that is guaranteed to be unique with a database. It is not a time portion of a DateTime or anything like it. If DataAdapter.Fill is having trouble determining the proper type then you'll need to define the DataColumns in your DataTable within the DataSet manually. The easiest way to do this is to create a typed DataSet using VS.NET. You can drag-n-drop tables, views, or stored procedures from Server Explorer (i.e., from connected databases) into the designer when you create a new DataSet type. Right-click on your project (or a folder within your project) and click Add->Add New Type. Then click "DataSet", give it a name, and click OK. Now you get what looks like (and actually is) the XML Schema designer. Drag any of those objects from the Server Explorer I mentioned above onto this surface, or design the tables and fields (elements and child elements) yourself. You can even add DataRelations and keys in this view as well. When you compile your project a typed DataSet is created. Instantiate a new instance of this DataSet instead of the base DataSet class. For performance improvements, use the typed table and column properties which decrease the number of required look-ups to find the correct table or column, respectively. On the other hand, you chould change the type in SQL Server. If you intended to have a field that stores just the time, then you need to declare it as a DateTime field in SQL Server. It's your views and what you do with the data that determine if the time, date, or both matter. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups