dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: ADO.NET 2.0: nullable column, but...

  1. #1
    Join Date
    Sep 2005
    Location
    Cracow, Poland
    Posts
    345

    Question ADO.NET 2.0: nullable column, but...

    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) {...}

  2. #2
    Join Date
    Dec 2009
    Posts
    6

    Re: ADO.NET 2.0: nullable column, but...

    One way to get more control of your data access routines is to just write them yourself using standard ADO .NET without dataadapters and ORM's. If you need help doing that, check out a trial version of a code generator I created at www.asteio.com. Even if you don't purchase the software after the trial period, you'll learn all the syntax to access your database with ADO .NET during the first 30 days.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)