Results 1 to 3 of 3

Thread: Inserting radio buttons values into a database

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Inserting radio buttons values into a database

    Hello,

    I have a database with 3 fields High and Low. The datatype in the database using MS Access is 'YesNo'.

    I have this code in Visual C#

    Code:
    OleDbCommand cmdInsert = cnnstrInsert.CreateCommand();
    cmdInsert.CommandType = CommandType.Text;
    cmdInsert.CommandText = @"INSERT INTO Customer(Customer, High, Low) VALUES('" + txtCustID.Text + "', '" + radHigh.Checked + "', "' + radLow.Checked + "') ";
    
    cmdInsert.ExecuteNonQuery();
    There is nothing wrong with the actual syntax, but how do l send the values for the radio buttons to the database.

    I keep getting a error msg say "incorrect datatype match". So started to do some testing and used this in the connection string instead.

    @"INSERT INTO Customer(Customer, High, Low) VALUES('" + txtCustID.Text + "', 'True', 'False') ";

    This still gave the same error.

    Can anyone tell me the correct way to insert the values of radio buttons into a database.

    Many thanks in advance,

    Steve
    steve

  2. #2
    Hyperactive Member Granty's Avatar
    Join Date
    Mar 2001
    Location
    London
    Posts
    439
    Have you tried the 2nd way but without quotes around the True and False?

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    No quotes around true/false - or put 0 for false and -1 for true...

    Not sure of C#'s syntax - vb one would be:

    VB Code:
    1. cmdInsert.CommandText = @"INSERT INTO Customer(Customer, High, Low) VALUES('" + txtCustID.Text + "', '" + (radHigh.Checked=true) + "', "' + (radLow.Checked=true) + "') ";
    .checked might be =1 - I can't remember


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

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



Click Here to Expand Forum to Full Width