c# - 我如何为 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");
解决方案
如果表格中的性别和接种疫苗字段是布尔值,则这些参数将执行以下操作:
command.Parameters.Add(new SqlParameter("@Gender", radioButton1.Checked);
command.Parameters.Add(new SqlParameter("@Vaccinated" checkBox1.Checked);
推荐阅读
- ios - Cordova 插件,带有原生故事板 UI
- python - 重复随机抽样;样本中位数的抽样分布
- file - 在 Dafny 中读取(写入)文件
- r - 错误:“df = read.csv(("/home/rstudio/IMDB_data.csv",”中的意外','
- java - Java Swing 中的 Word Wrap 与 Hard Wrap 像素限制
- parsing - Decoding a proprietary HEVC/MP4 stream
- php - laravel 5.7 登录程序问题
- css - 顶部带有@import 的全局scss 变量
- ios - 如何从嵌入在 UIScrollView 中的 UiView 中的 CollectionView 接收触摸事件
- c - 在 C 中将字符串文字作为参数传递时的分段错误