Professional Web Applications Themes

ASP.NET Insert into bit datatype - Adobe Dreamweaver & Contribute

Hey, I'm using ASP.NET vb and sql server 2000, basically I have a form with a few yes/no radio buttons and they insert into table with bit field types. Now for some reason if the yes/no radio buttons are left blank the form inserts a 0 or false into the fields. It should insert nothing since the those radio button were left blank and the table accepts nulls for those fields. This seems to only happen with the field type of bit not with any of the other nvarchar fields. Any ideas would be appreciated, thanks....

  1. #1

    Default ASP.NET Insert into bit datatype

    Hey,
    I'm using ASP.NET vb and sql server 2000, basically I have a form with a few
    yes/no radio buttons and they insert into table with bit field types. Now for
    some reason if the yes/no radio buttons are left blank the form inserts a 0 or
    false into the fields. It should insert nothing since the those radio button
    were left blank and the table accepts nulls for those fields. This seems to
    only happen with the field type of bit not with any of the other nvarchar
    fields. Any ideas would be appreciated, thanks.

    RajDogLives Guest

  2. #2

    Default Re: ASP.NET Insert into bit datatype

    > I'm using ASP.NET vb and sql server 2000, basically I have a form with a
    few
    > yes/no radio buttons and they insert into table with bit field types. Now
    for
    > some reason if the yes/no radio buttons are left blank the form inserts a
    0 or
    > false into the fields. It should insert nothing since the those radio
    button
    > were left blank and the table accepts nulls for those fields.
    A bit only has two states...on or off. NULL isn't really a state that it can
    have (even though you do allow null values).

    If you want to insert a null value, then you will have to explicitly check
    for that and then insert it as a null value.

    -Darrel


    darrel Guest

  3. #3

    Default Re: ASP.NET Insert into bit datatype

    Do you know the syntax? I'm new to asp.net, here is what dreamweaver has put in
    for me:
    I have tried a few different things but they are not working.
    Thanx

    <Parameter Name="FormerStudent" Value='<%# IIf((Request.Form("rbListFormer")
    <> Nothing), Request.Form("rbListFormer"), "") %>' Type="Bit" />

    RajDogLives Guest

  4. #4

    Default Re: ASP.NET Insert into bit datatype

    Can't you eliminate the nulls? They don't really make sense with a bit
    field.

    <Parameter Name="FormerStudent" Value='<%#
    IIf((Request.Form("rbListFormer") <> Nothing), 1, 0) %>' Type="Bit" />

    "RajDogLives" <webforumsusermacromedia.com> wrote in message
    news:d6j0e2$3b2$1forums.macromedia.com...
    > Do you know the syntax? I'm new to asp.net, here is what dreamweaver has
    > put in
    > for me:
    > I have tried a few different things but they are not working.
    > Thanx
    >
    > <Parameter Name="FormerStudent" Value='<%#
    > IIf((Request.Form("rbListFormer")
    > <> Nothing), Request.Form("rbListFormer"), "") %>' Type="Bit" />
    >

    Les Matthews Guest

  5. #5

    Default Re: ASP.NET Insert into bit datatype

    Hi

    I had a similar issue, I sorted it with

    <Parameter Name="FormerStudent" Value='<%# me.myFormname.checked %>'
    Type="Bit" />

    If checked enters a 1 else a 0

    Dave

    "Les Matthews" <LesAMatthews> wrote in message
    news:d6j3gb$77r$1forums.macromedia.com...
    > Can't you eliminate the nulls? They don't really make sense with a bit
    > field.
    >
    > <Parameter Name="FormerStudent" Value='<%#
    > IIf((Request.Form("rbListFormer") <> Nothing), 1, 0) %>' Type="Bit" />
    >
    > "RajDogLives" <webforumsusermacromedia.com> wrote in message
    > news:d6j0e2$3b2$1forums.macromedia.com...
    > > Do you know the syntax? I'm new to asp.net, here is what dreamweaver has
    > > put in
    > > for me:
    > > I have tried a few different things but they are not working.
    > > Thanx
    > >
    > > <Parameter Name="FormerStudent" Value='<%#
    > > IIf((Request.Form("rbListFormer")
    > > <> Nothing), Request.Form("rbListFormer"), "") %>' Type="Bit" />
    > >
    >
    >

    dizzy Guest

  6. #6

    Default Re: ASP.NET Insert into bit datatype

    Thanks for the input,
    I need the nulls because it's form input from questions that are not required.
    The form as is already inputs a 0 if there are no radio buttons checked but I
    want it to insert a null, which is easy directly in the db but through the form
    is giving me trouble. I think it is:

    IIf((Request.Form("rbListFormer") <> Nothing), Request.Form("rbListFormer"),
    "")

    I've tried
    IIf((Request.Form("rbListFormer") <> Nothing), Request.Form("rbListFormer"),
    "DBNull")
    IIf((Request.Form("rbListFormer") <> Nothing), Request.Form("rbListFormer"),
    "DBNull.Value")
    IIf((Request.Form("rbListFormer") <> Nothing), Request.Form("rbListFormer"),
    "Nothing")
    and of course
    IIf((Request.Form("rbListFormer") <> Nothing), Request.Form("rbListFormer"),
    "Null")

    But I can't get it. I might just change the type but I'm annoyed that it won't
    work.

    RajDogLives Guest

  7. #7

    Default Re: ASP.NET Insert into bit datatype

    Try DBNull without the quotes.
    It's just a guess, really. I'm not .NET savvy, but I know with regular ASP,
    anything in quotes is a string. You have to leave quotes off to use
    constants like Null, Empty, etc.

    "RajDogLives" <webforumsusermacromedia.com> wrote in message
    news:d6ksq7$mho$1forums.macromedia.com...
    > Thanks for the input,
    > I need the nulls because it's form input from questions that are not
    > required.
    > The form as is already inputs a 0 if there are no radio buttons checked
    > but I
    > want it to insert a null, which is easy directly in the db but through the
    > form
    > is giving me trouble. I think it is:
    >
    > IIf((Request.Form("rbListFormer") <> Nothing),
    > Request.Form("rbListFormer"),
    > "")
    >
    > I've tried
    > IIf((Request.Form("rbListFormer") <> Nothing),
    > Request.Form("rbListFormer"),
    > "DBNull")
    > IIf((Request.Form("rbListFormer") <> Nothing),
    > Request.Form("rbListFormer"),
    > "DBNull.Value")
    > IIf((Request.Form("rbListFormer") <> Nothing),
    > Request.Form("rbListFormer"),
    > "Nothing")
    > and of course
    > IIf((Request.Form("rbListFormer") <> Nothing),
    > Request.Form("rbListFormer"),
    > "Null")
    >
    > But I can't get it. I might just change the type but I'm annoyed that it
    > won't
    > work.
    >

    Lionstone Guest

  8. #8

    Default Re: ASP.NET Insert into bit datatype

    Oops that was a typo, I tried all of those without the quotes first and then with the quotes. Good catch though your right.
    RajDogLives Guest

  9. #9

    Default Re: ASP.NET Insert into bit datatype

    > Do you know the syntax? I'm new to asp.net, here is what dreamweaver has
    put in
    > for me:
    Well, I'm a bit confused. If you are using radio buttons, then one of the
    two NEEDS to be selected. That's how radio buttons work. There really never
    would be a null value.

    But, anyways, the SQL syntax for inserting a null value is:

    INSERT INTO yourTable (yourfield) VALUES (NULL);

    So, set up your code insert as:

    -Darrel


    darrel Guest

  10. #10

    Default Re: ASP.NET Insert into bit datatype

    Hmmm well an example where radio button may not need to be selected is if I had
    a questionaire where there were questions that where not required or optional.
    I would not want questions that weren't answered to all show up as false, I
    would want them to show up as unanswered.
    As far as the syntax I'm looking for asp.net syntax, dreamweaver also doesn't
    use normal insert syntax it uses custom controls to perform all inserts. The
    insert statement is a basic sql parameterized insert but it is assigning the
    correct asp.net null value to the parameter that I'm having a problem with. The
    SQL insert is:


    INSERT INTO dbo.tblInfoRequest (FirstName, LastName, Address1, Address2,
    AptNum, City, ""State"", Zip, Country, Email, DateofBirth, FormerStudent,
    PostSecondary, SchoolName, GradDate, AreaOfInterest, Athletics, Comments)
    VALUES (FirstName, LastName, Address1, Address2, AptNum, City, State,
    Zip, Country, Email, DateofBirth, FormerStudent, PostSecondary,
    SchoolName, GradDate, AreaOfInterest, Athletics, Comments)

    Thats not the problems its in:

    <Parameter Name="FormerStudent" Value='<%#
    IIf((Request.Form("rbListFormerQCC") <> Nothing),
    Request.Form("rbListFormerQCC"), DBNull.Value) %>' Type="Bit" />
    <Parameter Name="PostSecondary" Value='<%#
    IIf((Request.Form("rbListPostSecond") <> Nothing),
    Request.Form("rbListPostSecond"), "") %>' Type="Bit" />

    It's in the IIF, DBNull.value or Nothing should work check out:

    [url]http://groups-beta.google.com/group/microsoft.public.dotnet.framework.adonet/bro[/url]
    wse_thread/thread/520aea1b46c52f56/4a1fee6104367db7?q=insert+null+asp.net+dbnull
    ..value+nothing+null&rnum=1&hl=en#4a1fee6104367db7

    RajDogLives Guest

Similar Threads

  1. question on new psql datatype
    By Yu Pan in forum PostgreSQL / PGSQL
    Replies: 2
    Last Post: January 24th, 12:14 AM
  2. Function for retreiving datatype
    By Brendan Jurd in forum PostgreSQL / PGSQL
    Replies: 13
    Last Post: January 11th, 09:00 AM
  3. citext datatype
    By Sim Zacks in forum PostgreSQL / PGSQL
    Replies: 0
    Last Post: January 2nd, 12:20 PM
  4. I think it's a datatype issue
    By Fox in forum ASP Database
    Replies: 11
    Last Post: January 7th, 09:01 PM
  5. Check datatype
    By Andrew Durstewitz in forum ASP
    Replies: 2
    Last Post: June 30th, 03:46 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139