如何使用ado.net在数据库中检索checkboxlist值 [英] how to retrive checkboxlist value in database using ado.net

查看:66
本文介绍了如何使用ado.net在数据库中检索checkboxlist值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在该项目中创建一个医疗应用程序当用户搜索特定患者注册号时,一切都很好。但没有检索复选框列表值,因为选中的iam搜索了这么多博客,但对我没有任何帮助

iam creating one medical application in that project everything is retrieve well when user search particular patient registration no. but not retrieving checkboxlist value as selected iam search out so many blogs but nothing helpful for me

推荐答案

人们实际上并没有在数据库中存储复选框列表值 ,它们存储数据,从UI中抽象出来。



基本上,你需要存储的是一些布尔数据,但是,因为这不是一个单独的布尔项,但我们记得你使用映射到复选框列表的一些数据(你最好正确映射它:-)),你可能需要更好的打包,因为布尔信息基本上是一点。



这是一篇关于这个主题的短文: http://www.sqlusa.com/bestpractices/ bitdatatype / [ ^ ]。



我不知道您的数据库架构提供更多建议。也许,真正的建议是:使用ADO.NET。 :-)



-SA
People don''t really store "check box list values" in databases, they store data, well abstracted from your UI.

Basically, what you need to store is some Boolean data, but, as this is not an individual Boolean item, but we remember that you work with some data mapped to a check box list (you better map it correctly :-)), you might need something better packed, as Boolean information is essentially one bit.

This is a nice short article on this topic: http://www.sqlusa.com/bestpractices/bitdatatype/[^].

I have no idea on your database schema to advice more. Perhaps, the real advice would be: use ADO.NET. :-)

—SA


这里是如何从数据库中检索checkboxlist值的解决方案使用ado.net



here is the solution how to retrieve checkboxlist value from database using ado.net

string retrieve;
                retrieve = sdr[17].ToString();
                checkedListBox1.ClearSelected();
                foreach (int chk in checkedListBox1.CheckedIndices)
                {

                    checkedListBox1.SetItemChecked(chk,false);

                }
                foreach (string item in retrieve.Split(','))
                {
                    string test;
                    test = item.Trim();
                    checkedListBox1.SetItemChecked(checkedListBox1.Items.IndexOf(test),true );

                }



和数据库中的insert checkboxlist值




and for insert checkboxlist value in database

string str;
                    string st="";

                  for (int x = 0; x < checkedListBox1.CheckedItems.Count; x++)
                  {

                      st += checkedListBox1.CheckedItems[x].ToString() + ",";


                  }
                  str = st.Remove(st.Length -1).Trim();



             cmd.Parameters.Add("@Electro_Therapy", SqlDbType.VarChar).Value = str.ToString();


这篇关于如何使用ado.net在数据库中检索checkboxlist值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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