Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

i debug my code,i need update the data.that time the data is not updated.it is going to save function..pls help.
This is my code;

C#
private void btnAdd_Click(object sender, EventArgs e)
       {

           if (txtUserID.Text.Trim() == string.Empty)
           {
               MessageBox.Show("Please Enter The UserID.!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
               return;
           }

           if (txtUserName.Text.Trim() == string.Empty)
           {
               MessageBox.Show("Please Enter The UserName.!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
               return;
           }




           SqlDataAdapter da = new SqlDataAdapter("Select * From Users ", ConfigurationSettings.AppSettings["TrafficDB"]);
           DataSet ds = new DataSet("MastData");
           da.FillSchema(ds, SchemaType.Source, "Users");
           da.Fill(ds, "Users");
           DataTable dt;
           dt = ds.Tables["Users"];

           DataRow drCurrent;
           try
           {
               if (Convert.ToInt32(txtUserID.Tag.ToString()) == 0)
                   txtUserID.Tag = 0;
           }
           catch (System.NullReferenceException ex)
           {

               txtUserID.Tag = 0;
           }


           drCurrent = dt.Rows.Find(Convert.ToInt32(txtUserID.Tag.ToString()));
           if (drCurrent != null)
           {


               drCurrent.BeginEdit();
               drCurrent["UserId"] = txtUserID.Text.Trim();
               drCurrent["UserName"] = txtUserName.Text.Trim();
               drCurrent["FullControl"] = Convert.ToByte(chkboxFullcontrol.CheckState);

               drCurrent["IntAdd"] = Convert.ToByte(chkboxSave.CheckState);

               drCurrent["IntDelete"] = Convert.ToByte(chkboxDelete.CheckState);

               drCurrent["Modify"] = Convert.ToByte(chkboxUpdate.CheckState);

               drCurrent["Download"] = Convert.ToByte(chkboxDownload.CheckState);

               drCurrent["IntPrint"] = Convert.ToByte(chkboxPrint.CheckState);
               drCurrent["DateCreated"] = DateTime.Today;
               drCurrent["Status"] = 1;
               drCurrent.EndEdit();
               SqlCommandBuilder objCommandBuilder = new SqlCommandBuilder(da);
               da.Update(ds, "Users");
               MessageBox.Show("Record updated successfully", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);

               fnFillTreeView();
               fnClearEntryFields();
           }
           else
           {
               drCurrent = dt.NewRow();
               drCurrent["UserId"] = txtUserID.Text.Trim();
               drCurrent["UserName"] = txtUserName.Text.Trim();

               drCurrent["IntAdd"] = Convert.ToByte(chkboxSave.CheckState);
               drCurrent["FullControl"] = Convert.ToByte(chkboxFullcontrol.CheckState);

               drCurrent["IntDelete"] = Convert.ToByte(chkboxDelete.CheckState);

               drCurrent["Modify"] = Convert.ToByte(chkboxUpdate.CheckState);

               drCurrent["Download"] = Convert.ToByte(chkboxDownload.CheckState);

               drCurrent["IntPrint"] = Convert.ToByte(chkboxPrint.CheckState);
               drCurrent["DateCreated"] = DateTime.Today;
               drCurrent["Status"] = 1;

               dt.Rows.Add(drCurrent);
               SqlCommandBuilder objCommandBuilder = new SqlCommandBuilder(da);
               da.Update(ds, "Users");
               MessageBox.Show("Record saved successfully", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
               fnFillTreeView();
               fnClearEntryFields();
           }


the data is directly go to save function.how to solve this problem..

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 2-Mar-13 21:59pm
v2
Comments
Sandeep Mewara 3-Mar-13 4:23am    
Atleast to me, your question is not clear. What exactly you are trying to do and where are you stuck?
siva 2013 3-Mar-13 5:52am    
update function is not working..
[no name] 3-Mar-13 8:46am    
You do not have a "save" function or an "update" function defined.

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