Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Dear All,

one penal two radiobuttons we select one radiobutton. selected radiobutton store in database how to write the code?


ASP.NET
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true" CodeFile="Exemption_uc_10_4.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <br />
<br />
<br />
<br />
<div align="center">
    <asp:Panel ID="Panel1" runat="server" Height="250px" style="margin-right: 20px" 
        Width="750px" BorderColor="BlueViolet" BorderStyle="Solid" >
    
<table class="style1">
            <tr>
                <td>
                    <asp:Label ID="Label1" runat="server" Text="April">
                </td>
                <td>
                    <asp:TextBox ID="txt10_April" runat="server">
                </td>
                
                <td>
                    <asp:Panel ID="Panel3" runat="server" BorderColor="#3366FF" BorderStyle="Solid">
                        <asp:RadioButton ID="RadioButton1" runat="server" Text="Metro" />
                        <asp:RadioButton ID="RadioButton2" runat="server" Text="Non-Metro" />
                    
                </td>
                <td>
                    <asp:Label ID="Label7" runat="server" Text="October">
                </td>
                <td>
                    <asp:TextBox ID="txt10_October" runat="server">
                </td>
                <td>
                    <asp:Panel ID="Panel9" runat="server" BorderColor="#3366FF" BorderStyle="Solid">
                        <asp:RadioButton ID="RadioButton57" runat="server" Text="Metro" />
                        <asp:RadioButton ID="RadioButton58" runat="server" Text="Non-Metro" />
                    
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label2" runat="server" Text="May">
                </td>
                <td>
                    <asp:TextBox ID="txt10_May" runat="server">
                </td>
                <td>
                    <asp:Panel ID="Panel4" runat="server" BorderColor="#3366FF" BorderStyle="Solid">
                        <asp:RadioButton ID="RadioButton47" runat="server" Text="Metro" />
                        <asp:RadioButton ID="RadioButton48" runat="server" Text="Non-Metro" />
                    
                </td>
                <td>
                    <asp:Label ID="Label8" runat="server" Text="November">
                </td>
                <td>
                    <asp:TextBox ID="txt10_November" runat="server">
                </td>
                <td>
                    <asp:Panel ID="Panel10" runat="server" BorderColor="#3366FF" 
                        BorderStyle="Solid">
                        <asp:RadioButton ID="RadioButton59" runat="server" Text="Metro" />
                        <asp:RadioButton ID="RadioButton60" runat="server" Text="Non-Metro" />
                    
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label3" runat="server" Text="June">
                </td>
                <td>
                    <asp:TextBox ID="txt10_June" runat="server">
                </td>
                <td>
                    <asp:Panel ID="Panel5" runat="server" BorderColor="#3366FF" BorderStyle="Solid">
                        <asp:RadioButton ID="RadioButton49" runat="server" Text="Metro" />
                        <asp:RadioButton ID="RadioButton50" runat="server" Text="Non-Metro" />
                    
                </td>
                <td>
                    <asp:Label ID="Label9" runat="server" Text="December">
                </td>
                <td>
                    <asp:TextBox ID="txt10_December" runat="server">
                </td>
                <td>
                    <asp:Panel ID="Panel11" runat="server" BorderColor="#3366FF" 
                        BorderStyle="Solid">
                        <asp:RadioButton ID="RadioButton61" runat="server" Text="Metro" />
                        <asp:RadioButton ID="RadioButton62" runat="server" Text="Non-Metro" />
                    
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label4" runat="server" Text="July">
                </td>
                <td>
                    <asp:TextBox ID="txt10_July" runat="server">
                </td>
                <td>
                    <asp:Panel ID="Panel6" runat="server" BorderColor="#3366FF" BorderStyle="Solid">
                        <asp:RadioButton ID="RadioButton51" runat="server" Text="Metro" />
                        <asp:RadioButton ID="RadioButton52" runat="server" Text="Non-Metro" />
                    
                </td>
                <td>
                    <asp:Label ID="Label10" runat="server" Text="January">
                </td>
                <td>
                    <asp:TextBox ID="txt10_January" runat="server">
                </td>
                <td>
                    <asp:Panel ID="Panel12" runat="server" BorderColor="#3366FF" 
                        BorderStyle="Solid">
                        <asp:RadioButton ID="RadioButton63" runat="server" Text="Metro" />
                        <asp:RadioButton ID="RadioButton64" runat="server" Text="Non-Metro" />
                    
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label5" runat="server" Text="August">
                </td>
                <td>
                    <asp:TextBox ID="txt10_August" runat="server">
                </td>
                <td>
                    <asp:Panel ID="Panel7" runat="server" BorderColor="#3366FF" BorderStyle="Solid">
                        <asp:RadioButton ID="RadioButton53" runat="server" Text="Metro" />
                        <asp:RadioButton ID="RadioButton54" runat="server" Text="Non-Metro" />
                    
                </td>
                <td>
                    <asp:Label ID="Label11" runat="server" Text="February">
                </td>
                <td>
                    <asp:TextBox ID="txt10_February" runat="server">
                </td>
                <td>
                    <asp:Panel ID="Panel13" runat="server" BorderColor="#3366FF" 
                        BorderStyle="Solid">
                        <asp:RadioButton ID="RadioButton65" runat="server" Text="Metro" />
                        <asp:RadioButton ID="RadioButton66" runat="server" Text="Non-Metro" />
                    
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label6" runat="server" Text="September">
                </td>
                <td>
                    <asp:TextBox ID="txt10_September" runat="server">
                </td>
                <td>
                    <asp:Panel ID="Panel8" runat="server" BorderColor="#3366FF" BorderStyle="Solid">
                        <asp:RadioButton ID="RadioButton55" runat="server" Text="Metro" />
                        <asp:RadioButton ID="RadioButton56" runat="server" Text="Non-Metro" />
                    
                </td>
                <td>
                    <asp:Label ID="Label12" runat="server" Text="March">
                </td>
                <td>
                    <asp:TextBox ID="txt10_March" runat="server">
                </td>
                <td>
                    <asp:Panel ID="Panel14" runat="server" BorderColor="#3366FF" 
                        BorderStyle="Solid">
                        <asp:RadioButton ID="RadioButton67" runat="server" Text="Metro" />
                        <asp:RadioButton ID="RadioButton68" runat="server" Text="Non-Metro" />
                    
                </td>
            </tr>
            <tr>
                <td colspan="6" style="text-align: center">
                    <asp:Button ID="btn10_Save" runat="server" Text="Save" 
                        onclick="btn10_Save_Click" />
                </td>
            </tr>
        </table>
        
        </div>


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;
using System.Data.SqlClient;
using System.Configuration;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn10_Save_Click(object sender, EventArgs e)
    {
        string ConnectionString = "Data Source=S\\SQLEXPRESS;Initial Catalog=Income_Tax;Integrated Security=true;";
        SqlConnection conn = new SqlConnection(ConnectionString);
        conn.Open();
       
        SqlCommand cmd = new SqlCommand("INSERT INTO exemption_10  VALUES ('" + txt10_April.Text + "', "
            + txt10_May.Text + ", '" 
            + txt10_June.Text + "', " 
            + txt10_July.Text + ", " 
            + txt10_August.Text + ", '" 
            + txt10_September.Text + "', '" 
            + txt10_October.Text + "', '"
             + txt10_November.Text + "', '"
              + txt10_December.Text + "', '"
               + txt10_January.Text + "', '"
                + txt10_February.Text + "', '"
                 + txt10_March.Text +")", conn);

            
            cmd.ExecuteNonQuery();
            conn.Close();

    }
}
Posted
Updated 8-May-12 8:34am
v3
Comments
R. Giskard Reventlov 8-May-12 13:59pm    
Reason for my vote of 1
Agh! My eyes!!! That is horrible! Please edit the question so that it is human-readable!!! You might also want to check that you've asked a coherent question.
Sergey Alexandrovich Kryukov 8-May-12 14:56pm    
Reason for my vote of 1
I want to unsee it.
--SA

1 solution

You question is a bit unclear, but I take it you are having trouble getting the row to insert. If so, a couple things to look at:

1. This line needs to have a single quote insert before the parenthesis to complete the syntax:
C#
+ txt10_March.Text +")", conn);

change to:
C#
+ txt10_March.Text +"')", conn);

Note: this method of creating sql statements will leave you exposed to sql injection attacks. To avoid that, I would recommend that you use parameters instead.

2. Are you certain this is the correct connection string? Try using a dot instead and see if that works:
C#
string ConnectionString = "Data Source=S\\SQLEXPRESS;Initial Catalog=Income_Tax;Integrated Security=true;";

change to:
C#
string ConnectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=Income_Tax;Integrated Security=true;";
 
Share this answer
 

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