Click here to Skip to main content
15,886,016 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
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
Posted
Updated 3-Jan-13 4:12am
v2
Comments
[no name] 3-Jan-13 10:24am    
Write the code for your checkbox list here. Also how are you searching
Atul Rokade 8-Jan-13 1:05am    
sheikh sir from insert checkboxlist value i write

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

str += checkedListBox1.CheckedItems[x].ToString() + ",";
str = str.TrimEnd(',');


}




cmd.Parameters.Add("@Electro_Therapy", SqlDbType.VarChar).Value = str.ToString();
this code so value insert like IFT,Waveinfo,IRR

from retreive checkboxlist value i write
for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
{
checkedListBox1.Items[i]= dt.Rows[i][17].ToString().Trim();

}
but it not working for me

iam searching at particular patient register no. retrieving values show as there textbox only
Sergey Alexandrovich Kryukov 3-Jan-13 18:30pm    
"Nothing helpful" is not informative. What's the problem?
—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
 
Share this answer
 
Comments
Atul Rokade 8-Jan-13 1:00am    
sir iam using ado.net only n my data store in IFT,Waveshort,light format in table that means comma separated values store in database
Sergey Alexandrovich Kryukov 8-Jan-13 9:24am    
Comma-separated but stored in database? Well, stop abusing the database...
—SA
Atul Rokade 8-Jan-13 11:59am    
sergey it means store in table :)
Sergey Alexandrovich Kryukov 8-Jan-13 12:37pm    
Store what? You mention comma-separated values. Why storing them?
—SA
Atul Rokade 9-Jan-13 2:52am    
store information of particular treatment like IFT,IRR,SWF this type of value store in table
here is the solution how to retrieve checkboxlist value from database using ado.net

C#
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 );

                }

and for insert checkboxlist value in database

C#
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();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900