Click here to Skip to main content
12,404,251 members (80,111 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL-server-2005 SQL-Server , +
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 4:00am
Updated 3-Jan-13 4:12am
v2
Comments
Sheikh Muhammad Haris 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
   
"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 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
   
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 :)
   
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
   
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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2016
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