Click here to Skip to main content
12,078,489 members (42,909 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#3.5
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;

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 2-Mar-13 21:59pm
Edited 2-Mar-13 22: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..
ThePhantomUpvoter 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160212.1 | Last Updated 3 Mar 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