|
-
Nov 5th, 2004, 07:57 AM
#1
Thread Starter
Frenzied Member
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
-
Nov 5th, 2004, 06:55 PM
#2
Frenzied Member
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.
-
Nov 6th, 2004, 08:20 AM
#3
Thread Starter
Frenzied Member
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
-
Nov 6th, 2004, 10:49 AM
#4
Frenzied Member
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?
-
Nov 8th, 2004, 12:49 PM
#5
Hyperactive Member
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
-
Nov 11th, 2004, 09:58 AM
#6
Thread Starter
Frenzied Member
Thanks for your help,
Steve
-
Dec 10th, 2009, 10:48 AM
#7
Junior Member
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?
-
Dec 15th, 2009, 11:25 AM
#8
Thread Starter
Frenzied Member
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.
-
Dec 15th, 2009, 03:11 PM
#9
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|