如何将单选按钮值插入数据库? [英] How can i insert radio button values into database?

查看:318
本文介绍了如何将单选按钮值插入数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将单选按钮值插入数据库?

大家好

我有三个单选按钮..我想插入一个单选按钮值,我会点击....给我一些代码...... 。

How can i insert radio button values into database?
Hi to all
I have three radio buttons .. and i want to insert one radio button values which i will click ....give me some code....

推荐答案

如果你只有三个RadioButton然后你创建if条件并获得它的值,

喜欢,

if You have only three RadioButton then you create if condition and get the value of it,
Like,
if (RadioButton1.Checked)
        {
            rbdtext = RadioButton1.Text;
        }
        else if (RadioButton2.Checked)
        {
            rbdtext = RadioButton2.Text;
        }
        else if (RadioButton3.Checked)
        {
            rbdtext = RadioButton3.Text;
        }

<asp:RadioButton ID="RadioButton1" runat="server" Text="First" GroupName="rbd" Checked="true"/>
<asp:RadioButton ID="RadioButton2" runat="server" Text="Second" GroupName="rbd"/>
<asp:RadioButton ID="RadioButton3" runat="server" Text="Third" GroupName="rbd"/>



而且你必须设置所有RadioButton'的GroupName是相同的。 (例如GroupName =abc)

希望它能帮到你。


And also you have to set all RadioButton''s GroupName are Same. (e.g GroupName="abc")
Hope It''s Help You.


将RadioButton值插入数据库。 [ ^ ]



如何将radiobutton值存储到sql server数据库中 [< a href =http://www.codeproject.com/Questions/246941/how-to-store-radiobutton-value-into-sql-server-dattarget =_ blanktitle =New Window> ^ ]

插入单选按钮值进入sqlserver数据库。 [ ^ ]
Insert RadioButton values into database.[^]

how to store radiobutton value into sql server database[^]
Inserting radio button values into sqlserver database.[^]


在您的代码隐藏中尝试此操作。

在aspx文件中如果你使用三个按钮的单选按钮列表然后使用它或如果你使用单独的单选按钮然后使用 rbtGender.Text



try this in your code-behind.
In aspx file if you use radio button list for three buttons then use this or if you use radio buttons individual then use rbtGender.Text

protected void Button1_Click(object sender, EventArgs e)
    {
        string cs = ConfigurationManager.ConnectionStrings["srinivasdb"].ConnectionString;
        SqlConnection cn = new SqlConnection(cs);
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = cn;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "insert into GenderSample values(@Name,@Email,@Gender)";
        cmd.Parameters.Clear();
        cmd.Parameters.AddWithValue("@Name", txtName.Text);
        cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
        cmd.Parameters.AddWithValue("@gender", rbtGender.SelectedValue);
        if (cn.State == ConnectionState.Closed)
            cn.Open();
        cmd.ExecuteNonQuery();
        cn.Close();
        lblmsg.Text = "Data entered successfully!!!";
    }


这篇关于如何将单选按钮值插入数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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