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]