本文介绍了如何在按钮clik上数据库表中的多个复选框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我使用了4个不同的复选框我希望将它们保存在数据库中点击按钮 怎么做这个.Pase帮助我。任何人谢谢.. 我尝试过: i我不使用此代码我不知道我是如何粘贴此代码的只有形式。 请看我的简单问题并帮助我 i am used 4 diffrent checkbox i want save them in database on button clickhow done this.Pease Help me.anyone Thank you..What I have tried:i am not use this code i dont know how do this i am paste this code for only formalty.Please see my simple question and help mefor (int i = 0; i <=CheckBoxList1.Items.Count-1; i++) { if (CheckBoxList1.Items[i].Selected) { if (str == "") { str = CheckBoxList1.Items[i].Text; } else { str += "," + CheckBoxList1.Items[i].Text; } } } con.Open(); SqlCommand cmd = new SqlCommand("insert into aa(a)values('" +str + "')", con); cmd.ExecuteNonQuery(); 推荐答案 String activity = ""; for (int i = 0; i < CheckBoxList1.Items.Count; i++) { if (CheckBoxList1.Items[i].Selected) { activity += CheckBoxList1.Items[i].Value + ","; } } activity = activity.TrimEnd(','); 在插入查询之前在按钮上使用此代码。 字符串活动是为你的Checkbox定义。你可以使用活动的任何名称实例,然后在插入查询中使用这个不同的活动。 喜欢这个 use this code on your button before insert query."String activity" is define for your Checkbox.you can use any name instance of "activity" then you use this difened activity in your insert query.Like thisString update = "update StdRegistration_db set Name= @name,ParentsName= @parentsname,DOB= @DOB,Gender=@Gender,ContactsNo= @contacts ,EmailID= @email,Address=address @,<big>Hobbies= @activity</big> where id=@id"; 这篇关于如何在按钮clik上数据库表中的多个复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-02 06:35