Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working on a survey, with radio buttons. I have gotten to the point where I can insert a value (RB5=5) into the database, but it is not the selected one on the form.

From the form I would like to select the radio button and have that number (value) post in my access database; Table-Columns: (Question1(Q1), Question2(Q2) ...).


Thank you for your help

What I have tried:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;

namespace ms_access_databasefile
{
    public partial class Survey : System.Web.UI.Page
    {
        string Q1 = "";
        OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\SHS\Downloadhold\AcDb2.mdb");
        OleDbCommand cmd = new OleDbCommand();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            con.Open();
            OleDbCommand cmd = new OleDbCommand("insert into Table2 (Q1) Values('"+RB5.Text+"')", con);
            int r = cmd.ExecuteNonQuery();
            con.Close();

            if (RB1.Checked == true)
            { Q1 = "1"; }
            if (RB2.Checked == true)
            { Q1 = "2"; }
            if (RB3.Checked == true)
            { Q1 = "3"; }
            if (RB4.Checked == true)
            { Q1 = "4"; }
            if (RB5.Checked == true)
            { Q1 = "5"; }
        }


    }

}
Posted
Updated 26-Dec-20 20:10pm
v4

1 solution

You're inserting "RB5.Text" (?) each time. RB's usually don't have ".Text"; they have .Content (which could be text).

Q1 needs to be set BEFORE the (db) insert, based on the Q1 reference.

RB1 - RB5 isChecked should be mutually exclusive (based on "grouping") but you test all of them all the time.
 
Share this answer
 
Comments
Rub5 27-Dec-20 9:30am    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900