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. Database & SysAdmin
  3. Database
  4. ADO.NET almost nullable column

ADO.NET almost nullable column

Scheduled Pinned Locked Moved Database
csharpdatabaseai-codinghelptutorial
5 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.
  • Y Offline
    Y Offline
    Yoyosch
    wrote on last edited by
    #1

    I have a table in my DB containing a column of type Datetime, which allows null values. I created DataSet on which I drag&droped this table. Everything was fine, DataTable with TableAdapter have been successfully created and are both working. When I select this column in this DataTable (on designer surface) it shows in properties that this column is indeed nullable (AllowDBNull: True). However ADO.NET generated false code for this example. Look at the following code: var t= new ABCTableAdapter().GetData(); ticket[0].MyNullableColumn -> this return 'Datetime' instead of 'Datetime?'. If a given record in DB has indeed null value in this column, then such code generates "StrongTypingException". So this is quite clear that ADO.NET made some mistakes in code generation. I tried deleting all DataSet and recreating it from scratch. Also I`m sure that my column really allows null values as some records have such value in this column. Could you please help me and tell how am I supposed to force ADO.NET to generate this code properly? I want the following code to compile: if (t[0].MyNullableColumn != DBNull.Value) {...}

    J M 2 Replies Last reply
    0
    • Y Yoyosch

      I have a table in my DB containing a column of type Datetime, which allows null values. I created DataSet on which I drag&droped this table. Everything was fine, DataTable with TableAdapter have been successfully created and are both working. When I select this column in this DataTable (on designer surface) it shows in properties that this column is indeed nullable (AllowDBNull: True). However ADO.NET generated false code for this example. Look at the following code: var t= new ABCTableAdapter().GetData(); ticket[0].MyNullableColumn -> this return 'Datetime' instead of 'Datetime?'. If a given record in DB has indeed null value in this column, then such code generates "StrongTypingException". So this is quite clear that ADO.NET made some mistakes in code generation. I tried deleting all DataSet and recreating it from scratch. Also I`m sure that my column really allows null values as some records have such value in this column. Could you please help me and tell how am I supposed to force ADO.NET to generate this code properly? I want the following code to compile: if (t[0].MyNullableColumn != DBNull.Value) {...}

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      This is why you don't use the drag and drop crap. It generates a method .IsMyNullableColunNull()

      1 Reply Last reply
      0
      • Y Yoyosch

        I have a table in my DB containing a column of type Datetime, which allows null values. I created DataSet on which I drag&droped this table. Everything was fine, DataTable with TableAdapter have been successfully created and are both working. When I select this column in this DataTable (on designer surface) it shows in properties that this column is indeed nullable (AllowDBNull: True). However ADO.NET generated false code for this example. Look at the following code: var t= new ABCTableAdapter().GetData(); ticket[0].MyNullableColumn -> this return 'Datetime' instead of 'Datetime?'. If a given record in DB has indeed null value in this column, then such code generates "StrongTypingException". So this is quite clear that ADO.NET made some mistakes in code generation. I tried deleting all DataSet and recreating it from scratch. Also I`m sure that my column really allows null values as some records have such value in this column. Could you please help me and tell how am I supposed to force ADO.NET to generate this code properly? I want the following code to compile: if (t[0].MyNullableColumn != DBNull.Value) {...}

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        Jamie is right, learn to use a proper DAL and get control of your application, don't rely on MS generated code! This may be a better option for you

        t[0].MyNullableColumn ?? DBNull.Value

        Never underestimate the power of human stupidity RAH

        Y 1 Reply Last reply
        0
        • M Mycroft Holmes

          Jamie is right, learn to use a proper DAL and get control of your application, don't rely on MS generated code! This may be a better option for you

          t[0].MyNullableColumn ?? DBNull.Value

          Never underestimate the power of human stupidity RAH

          Y Offline
          Y Offline
          Yoyosch
          wrote on last edited by
          #4

          Sure sure, its the best to write everything in assembler or even machine code. Such approach is senseless. ADO's designer saved me a lot of time during many years, this is first time it fails. Still a very good result.

          M 1 Reply Last reply
          0
          • Y Yoyosch

            Sure sure, its the best to write everything in assembler or even machine code. Such approach is senseless. ADO's designer saved me a lot of time during many years, this is first time it fails. Still a very good result.

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            Yoyosch wrote:

            Sure sure, its the best to write everything in assembler or even machine code.

            Actually thats a bloody silly statement, I'm talking about the framework you use every day.

            Yoyosch wrote:

            ADO's designer saved me a lot of time during many years, this is first time it fails

            This would seem to indicate that you are doing fairly straight forward CRUD operations. We see this type of problem in the forums regularly, and yes it is generally something slightly different. IMHO it is not the productive issues, the designer/wizard stuff does make it quick and simple, it is the lack of any deep knowledge about your data and tools.

            Never underestimate the power of human stupidity RAH

            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