Results 1 to 9 of 9

Thread: Inserting radio buttons values into a database [* resolved *]

  1. #1

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

    Inserting radio buttons values into a database [* resolved *]

    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
    Last edited by steve_rm; Nov 11th, 2004 at 09:58 AM.
    steve

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    I'm not sure if this will help you or not, but I'm working on the same thing, almost. In my case the radio buttons are defined by the user and I build the controls at run time. Since I have no idea what the values/how many options there will be. So I figured I'd just save the text of the selected radio button.

  3. #3

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

    Thanks for your reply.

    The only thing l have managed to find out is that if i use this SQL statement instead by replacing radHigh.Checked with just a 1 or a 0 for true and false. That worked ok. I have my database datatype set to YesNo in MS access. I also tried this as well, but it did not work ('" + radHigh.Checked + "').

    If anyone can come up with a possible solution, please let me know.

    Thanks in advance,

    Steve
    steve

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    I don't use Access, but if it will take a 0 or a 1, can't you just put in a 0 if not checked, and a 1 if it is checked?

  5. #5
    Hyperactive Member
    Join Date
    Jun 2002
    Location
    Tulsa,Ok
    Posts
    262
    A YesNo in Access is the same as a byte in SQL. Add this into your SQL statement and this should do the trick.

    Code:
    Convert.ToByte(radioButton1.Checked)
    Also, take the single quotes out of your statement. These fields are not text or chars so the single quotes are not needed.

    Hope this helps,

    Jerel

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331
    Thanks for your help,

    Steve
    steve

  7. #7
    Junior Member
    Join Date
    Sep 2005
    Posts
    27

    Re: Inserting radio buttons values into a database [* resolved *]

    how do i insert Radio box value into the database. for example, S=Small, M=Medium or L=Large?

  8. #8

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

    Re: Inserting radio buttons values into a database [* resolved *]

    Hello,

    This is a old post.

    I will have to review and get back to you in a few days.
    steve

  9. #9
    Junior Member
    Join Date
    Sep 2005
    Posts
    27

    Re: Inserting radio buttons values into a database [* resolved *]

    I have figure it out
    Code:
    if (radSmall.Checked)
                {
                    strRAD = "S";
                }
    
    if (radMid.Checked)
                {
                    strRAD = "M";
                }
    if (radLG.Checked)
                {
                    strRAD = "L";
                }
    
    Print 'strRAD' into the database

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