Click here to Skip to main content
11,715,425 members (79,343 online)
Rate this: bad
good
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 20:59pm
Edited 2-Mar-13 21:59pm
(no name)1.3M
v2
Comments
Sandeep Mewara at 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 at 3-Mar-13 5:52am
   
update function is not working..
ThePhantomUpvoter at 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
0 Sergey Alexandrovich Kryukov 485
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 785
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320


Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 3 Mar 2013
Copyright © CodeProject, 1999-2015
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