How to Refresh Datagrid Control?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TWFyaw==?=

    How to Refresh Datagrid Control?

    Hi -

    I'm having trouble refreshing a datagrid control bound to a dataset that was
    created from the New Data Source wizard. What is the code required to
    refresh the datagrid with data from the data source (sql db)?

    More Details:

    The application is C# Windows (VS 2005).

    I used the "Add New Data Source" wizard to connect to a sql database and
    select the tables to include in the in-memory dataset.

    From the Data Source window, I selected a table, designated it as a datagrid
    and then dragged it onto the form. So far so good. The form runs fine, the
    data grid populates properly.

    Now I want to refresh the datagrid control. (I know the sql db has updated
    (values changed, new records inserted), after the form was started.) I have
    added a button to the form (named "Refresh Grid") and want to add code to
    it's click event to do the refreshing. My question is what is the code that
    is needed to requery the sql database?

    Thanks for your suggestions.
    Mark
  • =?Utf-8?B?RnJhbmsgVXJheQ==?=

    #2
    RE: How to Refresh Datagrid Control?

    Hi

    I think you first have to reload the DataSet,
    the grid will refresh automaticaly when DataSet is changed.

    Frank


    "Mark" wrote:
    Hi -
    >
    I'm having trouble refreshing a datagrid control bound to a dataset that was
    created from the New Data Source wizard. What is the code required to
    refresh the datagrid with data from the data source (sql db)?
    >
    More Details:
    >
    The application is C# Windows (VS 2005).
    >
    I used the "Add New Data Source" wizard to connect to a sql database and
    select the tables to include in the in-memory dataset.
    >
    From the Data Source window, I selected a table, designated it as a datagrid
    and then dragged it onto the form. So far so good. The form runs fine, the
    data grid populates properly.
    >
    Now I want to refresh the datagrid control. (I know the sql db has updated
    (values changed, new records inserted), after the form was started.) I have
    added a button to the form (named "Refresh Grid") and want to add code to
    it's click event to do the refreshing. My question is what is the code that
    is needed to requery the sql database?
    >
    Thanks for your suggestions.
    Mark

    Comment

    • =?Utf-8?B?TWFyaw==?=

      #3
      RE: How to Refresh Datagrid Control?

      Frank -

      Would you suggest the code that I need to use to "refresh" the dataset?

      I'm at a loss.

      Thanks,
      Mark

      "Frank Uray" wrote:
      Hi
      >
      I think you first have to reload the DataSet,
      the grid will refresh automaticaly when DataSet is changed.
      >
      Frank
      >
      >
      "Mark" wrote:
      >
      Hi -

      I'm having trouble refreshing a datagrid control bound to a dataset that was
      created from the New Data Source wizard. What is the code required to
      refresh the datagrid with data from the data source (sql db)?

      More Details:

      The application is C# Windows (VS 2005).

      I used the "Add New Data Source" wizard to connect to a sql database and
      select the tables to include in the in-memory dataset.

      From the Data Source window, I selected a table, designated it as a datagrid
      and then dragged it onto the form. So far so good. The form runs fine, the
      data grid populates properly.

      Now I want to refresh the datagrid control. (I know the sql db has updated
      (values changed, new records inserted), after the form was started.) I have
      added a button to the form (named "Refresh Grid") and want to add code to
      it's click event to do the refreshing. My question is what is the code that
      is needed to requery the sql database?

      Thanks for your suggestions.
      Mark

      Comment

      • =?Utf-8?B?RnJhbmsgVXJheQ==?=

        #4
        RE: How to Refresh Datagrid Control?

        Hi Mark

        I do not know your code ...
        Normaly you would fill a grid like this:

        **************

        // Variables
        public System.Data.Sql Client.SqlConne ction return_SQLNATIV EConnection = new
        System.Data.Sql Client.SqlConne ction();

        // Create Connection
        return_SQLNATIV EConnection.Con nectionString = "Data
        Source=SQLServe r\SQLInstance;I nitial Catalog=SQLData base;Integrated
        Security=SSPI;" ;
        return_SQLNATIV EConnection.Ope n();

        // DataAdapter erstellen
        System.Data.Sql Client.SqlDataA dapter local_DataAdapt er = new
        System.Data.Sql Client.SqlDataA dapter("SELECT * FROM Table",
        return_SQLNATIV EConnection);

        // DataSet erstellen
        System.Data.Dat aSet local_DataSet = new System.Data.Dat aSet();

        // DataSet füllen
        local_DataAdapt er.SelectComman d.CommandTimeou t = 0
        local_DataAdapt er.Fill(local_D ataSet, "DataSetTableNa me");

        // Grid füllen
        this.YourDataGr id.DataSource = local_DataSet

        **************

        For reload/refresh just run this code.

        Best regards
        Frank

        "Mark" wrote:
        Frank -
        >
        Would you suggest the code that I need to use to "refresh" the dataset?
        >
        I'm at a loss.
        >
        Thanks,
        Mark
        >
        "Frank Uray" wrote:
        >
        Hi

        I think you first have to reload the DataSet,
        the grid will refresh automaticaly when DataSet is changed.

        Frank


        "Mark" wrote:
        Hi -
        >
        I'm having trouble refreshing a datagrid control bound to a dataset that was
        created from the New Data Source wizard. What is the code required to
        refresh the datagrid with data from the data source (sql db)?
        >
        More Details:
        >
        The application is C# Windows (VS 2005).
        >
        I used the "Add New Data Source" wizard to connect to a sql database and
        select the tables to include in the in-memory dataset.
        >
        From the Data Source window, I selected a table, designated it as a datagrid
        and then dragged it onto the form. So far so good. The form runs fine, the
        data grid populates properly.
        >
        Now I want to refresh the datagrid control. (I know the sql db has updated
        (values changed, new records inserted), after the form was started.) I have
        added a button to the form (named "Refresh Grid") and want to add code to
        it's click event to do the refreshing. My question is what is the code that
        is needed to requery the sql database?
        >
        Thanks for your suggestions.
        Mark

        Comment

        • =?Utf-8?B?TWFyaw==?=

          #5
          RE: How to Refresh Datagrid Control?

          Frank -

          Thanks for the code. I can use this (and probably will end up using it if I
          can't figure it out (see below)).

          In my initial question I mentioned that I used the Add New Data Source
          wizard. This process created the connection and a typed dataset for me
          without any coding from me at all --- which is great and nice. It seems to
          me that I should be able to refresh the dataset somehow, leveraging the code
          generated by the wizard.

          For example, soemthing like this (which doesn't work) would be great.
          local_Dataset.c lear();
          local_Dataset.m ydatatableTable Adaptor.GetData ();

          So yeah I can use the code you supplied but then I wonder why I bothered
          using the wizard in the first place.

          Again, thanks for your suggestions.

          Mark









          "Frank Uray" wrote:
          Hi Mark
          >
          I do not know your code ...
          Normaly you would fill a grid like this:
          >
          **************
          >
          // Variables
          public System.Data.Sql Client.SqlConne ction return_SQLNATIV EConnection = new
          System.Data.Sql Client.SqlConne ction();
          >
          // Create Connection
          return_SQLNATIV EConnection.Con nectionString = "Data
          Source=SQLServe r\SQLInstance;I nitial Catalog=SQLData base;Integrated
          Security=SSPI;" ;
          return_SQLNATIV EConnection.Ope n();
          >
          // DataAdapter erstellen
          System.Data.Sql Client.SqlDataA dapter local_DataAdapt er = new
          System.Data.Sql Client.SqlDataA dapter("SELECT * FROM Table",
          return_SQLNATIV EConnection);
          >
          // DataSet erstellen
          System.Data.Dat aSet local_DataSet = new System.Data.Dat aSet();
          >
          // DataSet füllen
          local_DataAdapt er.SelectComman d.CommandTimeou t = 0
          local_DataAdapt er.Fill(local_D ataSet, "DataSetTableNa me");
          >
          // Grid füllen
          this.YourDataGr id.DataSource = local_DataSet
          >
          **************
          >
          For reload/refresh just run this code.
          >
          Best regards
          Frank
          >
          "Mark" wrote:
          >
          Frank -

          Would you suggest the code that I need to use to "refresh" the dataset?

          I'm at a loss.

          Thanks,
          Mark

          "Frank Uray" wrote:
          Hi
          >
          I think you first have to reload the DataSet,
          the grid will refresh automaticaly when DataSet is changed.
          >
          Frank
          >
          >
          "Mark" wrote:
          >
          Hi -

          I'm having trouble refreshing a datagrid control bound to a dataset that was
          created from the New Data Source wizard. What is the code required to
          refresh the datagrid with data from the data source (sql db)?

          More Details:

          The application is C# Windows (VS 2005).

          I used the "Add New Data Source" wizard to connect to a sql database and
          select the tables to include in the in-memory dataset.

          From the Data Source window, I selected a table, designated it as a datagrid
          and then dragged it onto the form. So far so good. The form runs fine, the
          data grid populates properly.

          Now I want to refresh the datagrid control. (I know the sql db has updated
          (values changed, new records inserted), after the form was started.) I have
          added a button to the form (named "Refresh Grid") and want to add code to
          it's click event to do the refreshing. My question is what is the code that
          is needed to requery the sql database?

          Thanks for your suggestions.
          Mark

          Comment

          • =?Utf-8?B?RnJhbmsgVXJheQ==?=

            #6
            RE: How to Refresh Datagrid Control?

            Hi Mark

            Well, the wizard also just creates some code.
            This code is possibly stored in FormXY.Designer .cs.
            And it works, when you open the form, the data is upToDate.

            Because a DataSet is something like a snapshot,
            "this.YourGridV iew.Refresh()" is not working ...
            It is refreshing against the DataSet and this is still the same.
            You first have to bring your DataSet UpToDate.

            Or you start using some external (not MS) components.
            I use Infragistics for all grid applications. Makes life easyer ... :-))

            Regards
            Frank

            Comment

            • =?Utf-8?B?TWFyaw==?=

              #7
              RE: How to Refresh Datagrid Control?

              Frank -

              Thanks for your comments.

              The following code did the trick [i.e., requeried the sql db]:
              this.mytableTab leAdapter.Fill( this.myDataset. mytable);

              In fact I had something like this yesterday but it did not work. In reality
              it was working but I didn't think it was since something else wasn't
              working... When I went back to a simple model "Fill" worked just fine, and I
              was able to work around that something else.

              Again thanks for your interest.

              Mark




              "Frank Uray" wrote:
              Hi Mark
              >
              Well, the wizard also just creates some code.
              This code is possibly stored in FormXY.Designer .cs.
              And it works, when you open the form, the data is upToDate.
              >
              Because a DataSet is something like a snapshot,
              "this.YourGridV iew.Refresh()" is not working ...
              It is refreshing against the DataSet and this is still the same.
              You first have to bring your DataSet UpToDate.
              >
              Or you start using some external (not MS) components.
              I use Infragistics for all grid applications. Makes life easyer ... :-))
              >
              Regards
              Frank
              >

              Comment

              Working...