saving a textbox into SQL Server

Posted on 2005-04-07
Last Modified: 2012-05-05
hey all---

I am a newbie here.  I am trying to write a SQL statement in ASP.NET to do an insert into a table on MS SQL Server.  My dilemma is that all of the fields in the table are ints and on the web form, they are all check boxes.  How can I set this up.  The username comes from a session.

strSQL = "INSERT INTO tblPurpose(username, check1, check2, check3, "
strSQL += "check4, check5, check6) VALUES('"
strSQL +=

where do i go from here?

Question by:rbgerman
    LVL 9

    Expert Comment

    strSQL = "INSERT INTO tblPurpose(username, check1, check2, check3, "
    strSQL += "check4, check5, check6) VALUES('"
    strSQL += Convert.ToInt32(yourCheckBox.Checked) + "," + Convert.ToInt32(checkBoxNo2.Checked).... etc
    LVL 9

    Accepted Solution

    don't wrap the values around semi quotes though... ie

    INSERT INTO tblPurpose(username, check1)  VALUES ("Rob", 1)


    strSQL = "INSERT INTO tblPurpose(username, check1, check2, check3, "
    strSQL += "check4, check5, check6) VALUES("
    strSQL += Convert.ToInt32(yourCheckBox.Checked) + "," + Convert.ToInt32(checkBoxNo2.Checked).... etc

    is what you want...  

    LVL 1

    Author Comment

    i am actually getting a server error.  my table has a PK of a uniquieidentifier, a varchar called username, and 6 checkboxes that are ints.  On the last line of the strSQL it gives the error of input string is not in correct format....what's up with that?



    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now