从 sql 获取数据到 checkboxlist 并将选定的框写回 sql
我是 C# 新手,正在开发注册页面。 我有sql,我可以从表到复选框列表获取游戏,效果很好,但是我不会将选定的复选框写回sql表,每个选定的复选框的值为1,
我尝试过使用此代码,
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected == true)
{
str += " " + CheckBoxList1.Items[i].ToString();
}
}
但是通过这个我得到了名称复选框为 1 个字符串
请帮忙
这是今天的表格
[1]: https://i.sstatic.net/vPVoX.png
如果选择 texas NL 1000/1000,我希望该游戏在所选列中具有值 1 只有 active = 1 的游戏才会显示在复选框列表中
在我在复选框列表中添加静态值并插入 sql 之前 但是现在,当我将游戏从数据库获取到页面(如果它们具有 active = 1)时,我现在不知道我的插入会是什么样子 这是旧的插入
string Sqlquery1 = "insert into [CashGame].[dbo].[tblStoGame] (Förnamn,EfterNamn,Datum,texas10_10,texas25_25,texas50_50,omaha10_10,omaha25_25,omaha50_50,Nickname,IDcard,MemberID) values ('" + Forename.Text + "','" + Lastname.Text + "',now(),'" + CheckBoxList1.Items[0].Selected + "','" + CheckBoxList1.Items[1].Selected + "','" + CheckBoxList1.SelectedItem.Value + "','" + Texas50_50 + "','" + Omaha10_10 + "','" + Omaha25_25 + "','" + Omaha50_50 + "','" + Nickname.Text + "','" + IDCard.Text + "','" + MemberID.Text + "')";
I'm new to c# and working on a registration page.
I have sql where i get games from table to checkboxlist, that works great, but then i wont to write the selected checkboxes back to sql table with value 1 for each selected checkbox
I have tried with this code
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected == true)
{
str += " " + CheckBoxList1.Items[i].ToString();
}
}
But with this i get the name of the checkboxes as 1 string
Please help
This is the table today
[1]: https://i.sstatic.net/vPVoX.png
If texas NL 1000/1000 is selected i want that game has the value 1 in selected column
It is only the games with active = 1 that is shown on the checkboxlist
Before i hade static values in checkboxlist and a insert into sql
But now when i get the games from database to page if they have active = 1 i dont now how my insert into i going to bee like
This is the old insert
string Sqlquery1 = "insert into [CashGame].[dbo].[tblStoGame] (Förnamn,EfterNamn,Datum,texas10_10,texas25_25,texas50_50,omaha10_10,omaha25_25,omaha50_50,Nickname,IDcard,MemberID) values ('" + Forename.Text + "','" + Lastname.Text + "',now(),'" + CheckBoxList1.Items[0].Selected + "','" + CheckBoxList1.Items[1].Selected + "','" + CheckBoxList1.SelectedItem.Value + "','" + Texas50_50 + "','" + Omaha10_10 + "','" + Omaha25_25 + "','" + Omaha50_50 + "','" + Nickname.Text + "','" + IDCard.Text + "','" + MemberID.Text + "')";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论