9
Reply

Having trouble refreshing database without restarting application

Joel Reid

Joel Reid

Nov 3 2009 4:49 PM
5k
I'm, for the most part, at a loss trying to figure out how to update this.

The scenario is that I am inserting some data on a form.  My insert button runs a command that inserts the data to a CallTracker table.

 public void LogCalltoDB(string technicianName, string territory, string emBod, string date, string callCategory)
        {

            string connectionString = ConfigurationSettings.AppSettings["Inventory2"].ToString();
            SqlConnection myCon = new SqlConnection(connectionString);

           
SqlCommand myCommand = new SqlCommand("INSERT INTO CallTracker
(techName, territoryID, problem, date, problemCategory) VALUES
(@technicianName, @territory, @emBod, @date, @callCategory)", myCon);

            myCommand.Parameters.Add(new SqlParameter("@technicianName", technicianName));
            myCommand.Parameters.Add(new SqlParameter("@territory", territory));
            myCommand.Parameters.Add(new SqlParameter("@emBod", emBod));
            myCommand.Parameters.Add(new SqlParameter("@date", date));
            myCommand.Parameters.Add(new SqlParameter("@callCategory", callCategory));

            myCon.Open();
            myCommand.ExecuteNonQuery();
            myCon.Close();
        }



So after this data gets inserted into my table, I want this to reflect changes on another tab where I search these log entries by a certain territory ID # without restarting my application.  I believe it makes a difference that I am using the tab control with 3 separate tabs.  The first tab is where I create and insert the entry, the 2nd tab is searching entries by territory ID and 3rd tab is searching by a tech name.

I've tried messing with the databindings as well as the tableadapter being updated and filled and still its not working unless I restart the application.

The code I use to search on my 2nd tab is

  try
  {
this.callTrackerTableAdapter.FillByTerritory(this.inventory2DataSet.CallTracker, new System.Nullable<int>(((int)(System.Convert.ChangeType(terrCallTextBox.Text,typeof(int))))));
  }
  catch (System.Exception ex)
  {
     System.Windows.Forms.MessageBox.Show(ex.Message);
  }


How can I change my code to refresh my table so I don't have to restart the application to search the log entries?

Thank you.  Joel

Answers (9)