一罚两个单选按钮,我们选择一个单选按钮 [英] one penal two radiobuttons we select one radiobutton

查看:50
本文介绍了一罚两个单选按钮,我们选择一个单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

一罚两个单选按钮,我们选择一个单选按钮.选定单选按钮存储在数据库中如何编写代码?


Dear All,

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


<%@ 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>





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();

    }
}

推荐答案

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:
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:
+ txt10_March.Text +")", conn);


change to:


change to:

+ 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:


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:

string ConnectionString = "Data Source=S\\SQLEXPRESS;Initial Catalog=Income_Tax;Integrated Security=true;";


change to:


change to:

string ConnectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=Income_Tax;Integrated Security=true;";


这篇关于一罚两个单选按钮,我们选择一个单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆