Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 3-Jan-13 5:00am
Edited 3-Jan-13 5:12am
v2
Comments
Sheikh Muhammad Haris at 3-Jan-13 10:24am
   
Write the code for your checkbox list here. Also how are you searching
Atul Rokade at 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 at 3-Jan-13 18:30pm
   
"Nothing helpful" is not informative. What's the problem?
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 Smile | :) ), 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. Smile | :)
 
—SA
  Permalink  
Comments
Atul Rokade at 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 at 8-Jan-13 9:24am
   
Comma-separated but stored in database? Well, stop abusing the database...
—SA
Atul Rokade at 8-Jan-13 11:59am
   
sergey it means store in table :)
Sergey Alexandrovich Kryukov at 8-Jan-13 12:37pm
   
Store what? You mention comma-separated values. Why storing them?
—SA
Atul Rokade at 9-Jan-13 2:52am
   
store information of particular treatment like IFT,IRR,SWF this type of value store in table
Sergey Alexandrovich Kryukov at 9-Jan-13 9:23am
   
Why?..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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 );
 
                }
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();
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 381
1 Sergey Alexandrovich Kryukov 245
2 Marcin Kozub 225
3 Praneet Nadkar 217
4 /\jmot 189
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100