Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update data in TextChanged event show message when retrieve data or show data

Status
Not open for further replies.

ahm1985

Programmer
Dec 6, 2012
138
EG
Hi guys I need to show message "record successfully updated" when i updated database only not every time
i retrieve data or show data
private void Driver_Load(object sender, EventArgs e)
{
string constr = "Data Source=" + value1 + ";Initial Catalog=" + value2 + ";User ID=" + value3 + ";Password=" + value4 + "";
con = new SqlConnection(constr);
string comdstr = "select * from Driver";
da = new SqlDataAdapter(comdstr, constr);
ds = new DataSet();
da.Fill(ds, "Driver");
dt = new DataTable();
dt = ds.Tables["Driver"];

totalrecord = dt.Rows.Count;


if (ds != null)
{
dt = ds.Tables[0];

currrecord = 0;
}
fillcontrol();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
FleetManagment.Fleet fleet1 = new FleetManagment.Fleet();
int a = fleet1.UpdateDriver("Data Source=" + value1 + ";Initial Catalog=" + value2 + ";User ID=" + value3 + ";Password=" + value4 + "", Convert.ToInt32(textBox1.Text), textBox2.Text, textBox3.Text, textBox4.Text);
if (a>0)
{
message box.show("record successfully updated");
}
My code above working without any problem
But my problem why message box.show("record successfully updated")
display in every time i retrieve data or showing data
the screen shoot problem found in this link below :
as rar file
Thanks
 
What I usually do in this situation is create a Boolean "flag" that is a protected variable in the class. In your case I'll call this variable "bLoading" and assume it's set to false in its declaration. I would then change your code to something like this:
Code:
private void Driver_Load(object sender, EventArgs e)
{
  bLoading = true;
  string constr = "Data Source=" + value1 + ";Initial Catalog=" + value2 + ";User ID=" + value3 + ";Password=" + value4 + "";
  con = new SqlConnection(constr);
  string comdstr = "select * from Driver";
  da = new SqlDataAdapter(comdstr, constr);
  ds = new DataSet();
  da.Fill(ds, "Driver");
  dt = new DataTable();
  dt = ds.Tables["Driver"];
  totalrecord = dt.Rows.Count;
  if (ds != null)
  {
    dt = ds.Tables[0];
    currrecord = 0;
  }
  fillcontrol();
  bLoading = false;
}
 
private void textBox2_TextChanged(object sender, EventArgs e)
{
  if (!bLoading)
  {
    FleetManagment.Fleet fleet1 = new FleetManagment.Fleet();
    int a = fleet1.UpdateDriver("Data Source=" + value1 + ";Initial Catalog=" + value2 + ";User ID=" + value3 + ";Password=" + value4 + "", Convert.ToInt32(textBox1.Text), textBox2.Text, textBox3.Text, textBox4.Text);
    if (a>0)
    {
      message box.show("record successfully updated");
    }
  }
}

-Dell

DecisionFirst Technologies - Seven-time SAP BusinessObjects Solution Partner of the Year
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top