首页 > 解决方案 > 我如何为 RadioButton 和 CheckBox 编码以将数据插入数据库

问题描述

我有写这段代码。但现在我不知道为单选按钮和复选框编写代码。请帮忙。

“性别”是一个单选按钮。“接种疫苗是一个复选框”

    private void buttonprint_Click(object sender, EventArgs e)
        {
            connection.Open();
            SqlCommand command = new SqlCommand();
            command.Connection = connection;
            command.CommandText = "insert into birth values(@applicanturdu,@applicantname, @applicantnic,@childurduname,@childname,@rishta,@relation,@gender,@cast,@sibling,
@religion,@walidname,@fathername,@fathernic,@walidaname,@mothername,@mothernic,@dadaname,@grandfather,@dadanic,@birthzilla,@birthdistrict,@birthdate,@vaccinate,@birthplace,@doctor,@disability,@education,@village,@uc,@vc,@tehsil,@district)";
            command.Parameters.Add(new SqlParameter("@applicanturdu", textBoxapplicanturdu.Text));
            command.Parameters.Add(new SqlParameter("@applicantname", textBoxbachaname.Text));
            command.Parameters.Add(new SqlParameter("@applicantnic", textBoxapplicantnic.Text));
            command.Parameters.Add(new SqlParameter("@Gender");
           command.Parameters.Add(new SqlParameter("@Vaccinated");

标签: c#sql-serverwinforms

解决方案


如果表格中的性别和接种疫苗字段是布尔值,则这些参数将执行以下操作: command.Parameters.Add(new SqlParameter("@Gender", radioButton1.Checked); command.Parameters.Add(new SqlParameter("@Vaccinated" checkBox1.Checked);


推荐阅读