Kavi suja

Kavi suja

  • NA
  • 298
  • 170.8k

CheckboxList - Update - StoredProcedure

Aug 2 2013 7:12 AM
Hi,
   I have table with 4 fields pkey,name,whosinfo_pkey,description.Here 'pkey' is autogenerated key. The sample values following here:
'75', 'Contact Dermatitis', '513', 'Contact Dermatitis'
'76', 'Anaphylaxis', '513', 'Anaphylaxis'
'77', 'Insect Venom', '513', 'Insect Venom'
'78', 'Atopic Dermatitis', '520', 'Atopic Dermatitis'
'79', 'Food Alergies', '520', 'Food Alergies'
'80', 'Insect Venom', '520', 'Insect Venom'

Here I want to update this table using whosinfo_pkey.I use following StoredProcedure for this
CREATE DEFINER=`root`@`%` PROCEDURE `SPUpdateMA`(in pkey varchar(45),


in DisName varchar(60)
)
BEGIN

UPDATE medicalhistory medhis
INNER JOIN whosinfo whos 
  ON whos.pkey=medhis.whosInfo_pkey

SET 
medhis.name=DisName,
/*medhis.whosInfo_pkey=pkey,*/
medhis.description=DisName
WHERE medhis.whosInfo_pkey=pkey;

END
In update button click I use following code:


try
                    {            
                       
                        if (whospkey == "")
                        {

                        }
                        else
                        {
                            //string patid = Request.QueryString["Ptid"];
                            for (int i = 0; i < CheckBoxList2.Items.Count; i++)
                            {
                                if (CheckBoxList2.Items[i].Selected == true)
                                {
                                    objReg.Name = CheckBoxList2.Items[i].Text;
                                    objReg.WhosInfo = whospkey;
                                    //  objReg.WhosInfo = Convert.ToString(ViewState["WhosInfo"]);                          
                                    objRegLogic.UpdatePMedHis(objReg);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {

                    }


In design page,I use checkboxlist as following:
 <asp:CheckBoxList ID="CheckBoxList2" runat="server" BorderStyle="Ridge" RepeatColumns="3"
                                    CssClass="CheckboxList" Width="100%" RepeatDirection="Horizontal" BorderColor="#3399FF">
                                </asp:CheckBoxList>

Here the problem is,when I update this it will update all data like following:
'75', 'Contact Dermatitis', '513', 'Contact Dermatitis'
'76', 'Anaphylaxis', '513', 'Anaphylaxis'
'77', 'Insect Venom', '513', 'Insect Venom'
'78', 'Anaphylaxis', '520', 'Anaphylaxis'
'79', 'Anaphylaxis', '520', 'Anaphylaxis'
'80', 'Anaphylaxis', '520', 'Anaphylaxis'


But actually I check 3 checkboxes.It takes last checkbox value only Hives,Food Allergies,Anaphylaxis.How I overcome this?How can I update values here correctly?Can anyone help me?
































Answers (5)