Great Ideas. Always Flowing.

We are not happy until you are happy. Client satisfaction guaranteed. Whatever your needs and requirements, we have the skills and resources for the job!

Quick login...


Or... now make it easy with Facebook Integration
Connect via Facebook



Top Sellers

Frustrated over the lack of customization for your user's registration fields? Dynamically setup your DNN Portal with custom registration fields, layout, questions, and other core integration options......

Ultra Video Gallery is a brother product of Ultra Media Gallery, UVG allows you to upload videos in various format and automatically encode them to flv or H264 format, you also can add videos from internet or record live videos from your webcam.

Build high performance, completely customizable data-entry forms and views driven by your DNN and external databases. New built-in tools make it a snap to quickly create data entry forms, data views, and even database tables. Plus, add your own HTML, CSS, Javascript, SQL commands, stored procedures,

The most advanced DotNetNuke shopping cart on the planet. Easy to use e-Commerce, Secure Shopping Cart Software and SEO friendly. B2C / B2B Ecommerce Sites.

One stop solution for events calendar and events registration! FREE DOWNLOAD is available now!

CheckBox bit conversion problem
Last Post 04-16-2009 04:54 PM by Nathan Botts. 10 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Nathan BottsUser is Offline
wading in the water
wading in the water
Posts:20
Avatar

--
04-09-2009 03:15 PM

    Hello,

    I am building a form that inserts into an existing table. I have a couple different checkboxes that I want to use. When I test the insert using the form debug against the existing table in my database it gives me the following error:

    "Conversion failed when converting the varchar value 'Yes' to data type bit."

    Is there a way to make it so that the CheckBox function in the form sends a bit versus a yes or no?

    David ToUser is Offline
    river guide
    river guide
    Posts:2719
    Avatar

    --
    04-10-2009 06:54 AM

    HI Nathan, yes you can create a store procedure for your insertion. In your SQL table, make sure the checkbox columns are of type bit (which only accepts values 0 or 1, 0 being unchecked, 1 being checked). Create a stored procedure like something:

    create procedure WriteToSQL (@checkbox nvarchar(10) )
    as
    begin
    declare @checkconvert bit
    if (@checkbox = 'Yes') set @checkconvert = 1 else set @checkconvert = 0
    insert into tablename(checkboxcolumn) values (@checkconvert)
    end

    Call this stored procedure in your form completion SQL event like:
    WriteToSQL '$(checkbox)'
    -- David

    Nathan BottsUser is Offline
    wading in the water
    wading in the water
    Posts:20
    Avatar

    --
    04-10-2009 07:20 AM

    Hi David,

     

    Great, I'm going to test this out today and will post back with my results.

     

    Thanks, Nathan

    Nathan BottsUser is Offline
    wading in the water
    wading in the water
    Posts:20
    Avatar

    --
    04-16-2009 10:14 AM

    Just so I am sure that I'm doing this correctly...the table that I am inserting to has three different columns with checkbox values. How do I properly insert into the multiple columns?

     

    Can I add them in here?

     

    "insert into tablename(checkboxcolumn, checkboxcolumn2, checkboxcolumn3) values (@checkconvert)
    end"

    David ToUser is Offline
    river guide
    river guide
    Posts:2719
    Avatar

    --
    04-16-2009 10:32 AM

    HI Nathan, no it would be like this:
    create procedure WriteToSQL (@checkbox1 nvarchar(10),@checkbox2 nvarchar(10),@checkbox3 nvarchar(10) )
    as
    begin
    declare @checkconvert1 bit
    declare @checkconvert2 bit
    declare @checkconvert3 bit
    if (@checkbox1 = 'Yes') set @checkconvert1 = 1 else set @checkconvert1 = 0
    if (@checkbox2 = 'Yes') set @checkconvert2 = 1 else set @checkconvert2 = 0
    if (@checkbox3 = 'Yes') set @checkconvert3 = 1 else set @checkconvert3 = 0
    insert into tablename(checkboxcolumn1,checkboxcolumn2,checkboxcolumn3) values (@checkconvert1,@checkconvert2,@checkconvert3)
    end

    Call this stored procedure in your form completion SQL event like:
    WriteToSQL '$(checkbox1)' ,'$(checkbox2)', '$(checkbox3)'

    -- David

    Nathan BottsUser is Offline
    wading in the water
    wading in the water
    Posts:20
    Avatar

    --
    04-16-2009 11:00 AM

    Ok great, thanks. So last confirmation...where exactly in the event should I call it. Here is what my event generally looks like (abbreviated). Do I place it at the very end like so...?

    INSERT INTO  [dbo].[user_tbl](
    [firstName],
    [middleName],
    [lastName],
    [checkbox1],
    [checkbox2],
    [checkbox3],
    )
    VALUES (
    '$(firstName)',
    '$(middleName)',
    '$(lastName)',
    '$(checkbox1)',
    '$(checkbox2)',
    '$(checkbox3)',
    WriteToSQL '$(checkbox1)' '$(checkbox2)' '$(checkbox3)'
    )

    David ToUser is Offline
    river guide
    river guide
    Posts:2719
    Avatar

    --
    04-16-2009 11:18 AM
    Nope, that's not the way to do it. Under HOST / SQL, you type in the entire stored procedure and execute the script. Then under your DF completion event with SQL chosen, you type in the store procedure name and pass the variables through. Under HOST / SQL:

    create procedure WriteToUserTable (@firstName nvarchar(30),@middleName nvarchar(30),@lastName nvarchar(30),@checkbox1 nvarchar(10),@checkbox2 nvarchar(10),@checkbox3 nvarchar(10) )
    as
    begin
    declare @checkconvert1 bit
    declare @checkconvert2 bit
    declare @checkconvert3 bit
    if (@checkbox1 = 'Yes') set @checkconvert1 = 1 else set @checkconvert1 = 0
    if (@checkbox2 = 'Yes') set @checkconvert2 = 1 else set @checkconvert2 = 0
    if (@checkbox3 = 'Yes') set @checkconvert3 = 1 else set @checkconvert3 = 0
    insert into user_tbl(firstName,middleName,lastName,checkbox1,checkbox2,checkbox3) values (@firstName,@middleName,@lastName,@checkconvert1,@checkconvert2,@checkconvert3)
    end

    In your DF form completion event, you call this store procedure, passing your tokens values:
    WriteToUserTable '$(firstName)','$(middleName)','$(lastName)','$(checkbox1)','$(checkbox2)','$(checkbox3)'
    Nathan BottsUser is Offline
    wading in the water
    wading in the water
    Posts:20
    Avatar

    --
    04-16-2009 11:29 AM
    Ohhhh, ok so I use the stored procedure to insert all my values. I think I got it now. Will postback with success.
    Nathan BottsUser is Offline
    wading in the water
    wading in the water
    Posts:20
    Avatar

    --
    04-16-2009 03:21 PM

    Not successful yet and not sure how to debug. Previously I would enable debugging and then test the insert in SSMS, but I'm not sure how to do this with the stored procedure.

    My procedure (abbreviated) looks like this:

    ----------------------------------------------------------------------------------

    Create PROCEDURE DNNConvert2Bit (@firstName nvarchar(50),@middleName nvarchar(50),@lastName nvarchar(50),@checkbox1 nvarchar(10),@checkbox2

    nvarchar(10),@checkbox3 nvarchar(10))
    as
    begin
    declare @checkconvert1 bit
    declare @checkconvert2 bit
    declare @checkconvert3 bit
    if (@checkbox1 = 'Yes') set @checkconvert1 = 1 else set @checkconvert1 = 0
    if (@checkbox2 = 'Yes') set @checkconvert2 = 1 else set @checkconvert2 = 0
    if (@checkbox3 = 'Yes') set @checkconvert3 = 1 else set @checkconvert3 = 0

    INSERT INTO User_tbl(firstName,middleName,lastName,checkbox1,checkbox2,checkbox3)

    VALUES (@firstName,@middleName,@lastName,@checkconvert1,@checkconvert2,@checkconvert3)
    end

    ------------------------------------------------------------------------------

    My SQL Event looks like this:

    DNNConvert2Bit
    '$(firstName)',
    '$(middleName)',
    '$(lastName)',
    '$(checkbox1)',
    '$(checkbox2)',
    '$(checkbox3)'
    )

    ----------------------------------------------------------

    The debug response I get in DF shows something like this:

    Executing SQL Event
    SQL Query: DNNConvert2Bit 'Scott', '', 'Apple', 'Yes', 'Yes', 'Yes' )

    --------------------------------------------

    I have executed the stored procedure in SSMS, entered some values and received an error that says:

    Msg 102, Level 15, State 1, Line 8

    Incorrect syntax near '/'.

    Any ideas on what I might be doing wrong?

     

    David ToUser is Offline
    river guide
    river guide
    Posts:2719
    Avatar

    --
    04-16-2009 04:34 PM
    You had an extra ")" at the end of the SQL event. It should be this:

    DNNConvert2Bit '$(firstName)','$(middleName)','$(lastName)','$(checkbox1)','$(checkbox2)','$(checkbox3)'
    Nathan BottsUser is Offline
    wading in the water
    wading in the water
    Posts:20
    Avatar

    --
    04-16-2009 04:54 PM

    Ahhhh the little things in life.

     

    That appeared to be it and all looks well in the db.

     

    Thanks so much for working through this with me.

     

    -Nathan

    You are not authorized to post a reply.


     
     

    Join our mailing list...

    Get current news and events the easy way
    Subscribe Me

    Recent Blogs...

     
    Copyright 2005 - 2011 by Data Springs, Inc.
     
  • film izle
  • 720 izle
  • film
  • sinema izle
  • film makinesi
  • T�rk�e dublaj film
  • film izle
  • film izle
  • baglan film izle
  • sinema izle
  • 1080 film izle
  • film mercegi