Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. handle data in GUI (datagridview) and database

handle data in GUI (datagridview) and database

Scheduled Pinned Locked Moved C#
databasequestionhardwareannouncement
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ronenb
    wrote on last edited by
    #1

    Hi All I need your advice what is the best solution to handle data I’m developing online logger application at windows that will be connected to hardware. The application should handle heavy traffic data( could be up to hundreds of events per second) The datagridview is active as viewer only (readonly). I need to develop mechanism of insert the events to DB and display them in the datagridview. I need your advice if this is correct approach? I’m thinking of using the flow below Init() { SqlConnection connection = new SqlConnection(connectionstring); connection.open() SqlDataAdapter adapter = new SqlDataAdapter("select * from TableName", connection); DataSet ds = new DataSet(); dataGridView1.DataSource = ds; ); } AddRow(data) { //Add to database string insertString = "insert into TableName (Field1, Field2) values (‘Value1’,’Value2’)"; // 1. Instantiate a new command with a query and connection SqlCommand cmd = new SqlCommand(insertString, connection); // 2. Call ExecuteNonQuery to send command cmd.ExecuteNonQuery(); } //each second the timer event occurs Timer () { adapter.Fill(ds,idxLastUpdatedRow,100/* update 100 records each time*/ ,tableName); dataGridView1.refresh() } Thanks Ronen

    OriginalGriffO P 2 Replies Last reply
    0
    • R Ronenb

      Hi All I need your advice what is the best solution to handle data I’m developing online logger application at windows that will be connected to hardware. The application should handle heavy traffic data( could be up to hundreds of events per second) The datagridview is active as viewer only (readonly). I need to develop mechanism of insert the events to DB and display them in the datagridview. I need your advice if this is correct approach? I’m thinking of using the flow below Init() { SqlConnection connection = new SqlConnection(connectionstring); connection.open() SqlDataAdapter adapter = new SqlDataAdapter("select * from TableName", connection); DataSet ds = new DataSet(); dataGridView1.DataSource = ds; ); } AddRow(data) { //Add to database string insertString = "insert into TableName (Field1, Field2) values (‘Value1’,’Value2’)"; // 1. Instantiate a new command with a query and connection SqlCommand cmd = new SqlCommand(insertString, connection); // 2. Call ExecuteNonQuery to send command cmd.ExecuteNonQuery(); } //each second the timer event occurs Timer () { adapter.Fill(ds,idxLastUpdatedRow,100/* update 100 records each time*/ ,tableName); dataGridView1.refresh() } Thanks Ronen

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      If you are talking about "hundreds of events per second" then do not even try to display them in real time: it will very quickly become a bottle neck. Display the last twenty: use a different thread to load the database and update the DataGridView from the UI thread on a timer. Who the heck do you expect to read hundreds of messages a second? I'm a reasonably fast reader (average novel in under two hours) but I wouldn't cope with that volume of data, and would go bonkers if I had to try from more than 30 seconds.

      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      M 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        If you are talking about "hundreds of events per second" then do not even try to display them in real time: it will very quickly become a bottle neck. Display the last twenty: use a different thread to load the database and update the DataGridView from the UI thread on a timer. Who the heck do you expect to read hundreds of messages a second? I'm a reasonably fast reader (average novel in under two hours) but I wouldn't cope with that volume of data, and would go bonkers if I had to try from more than 30 seconds.

        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        OriginalGriff wrote:

        average novel in under two hours

        Man your reading habit must be bloody expensive. 100s of rows a second, I don't think you could even focus comfortably on the data!

        Never underestimate the power of human stupidity RAH

        OriginalGriffO 1 Reply Last reply
        0
        • M Mycroft Holmes

          OriginalGriff wrote:

          average novel in under two hours

          Man your reading habit must be bloody expensive. 100s of rows a second, I don't think you could even focus comfortably on the data!

          Never underestimate the power of human stupidity RAH

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          It was, in space alone! :laugh:

          Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          R 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            It was, in space alone! :laugh:

            Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

            R Offline
            R Offline
            Ronenb
            wrote on last edited by
            #5

            I'm develop a online logger monitor, i know the user could be able to read the db in the grid The grid will be update each second with amount of data that I will define (such as 200 events) i'm asking about the Implementation ronen

            1 Reply Last reply
            0
            • R Ronenb

              Hi All I need your advice what is the best solution to handle data I’m developing online logger application at windows that will be connected to hardware. The application should handle heavy traffic data( could be up to hundreds of events per second) The datagridview is active as viewer only (readonly). I need to develop mechanism of insert the events to DB and display them in the datagridview. I need your advice if this is correct approach? I’m thinking of using the flow below Init() { SqlConnection connection = new SqlConnection(connectionstring); connection.open() SqlDataAdapter adapter = new SqlDataAdapter("select * from TableName", connection); DataSet ds = new DataSet(); dataGridView1.DataSource = ds; ); } AddRow(data) { //Add to database string insertString = "insert into TableName (Field1, Field2) values (‘Value1’,’Value2’)"; // 1. Instantiate a new command with a query and connection SqlCommand cmd = new SqlCommand(insertString, connection); // 2. Call ExecuteNonQuery to send command cmd.ExecuteNonQuery(); } //each second the timer event occurs Timer () { adapter.Fill(ds,idxLastUpdatedRow,100/* update 100 records each time*/ ,tableName); dataGridView1.refresh() } Thanks Ronen

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              I hope you're not expecting to have one app that does both the gathering and the displaying. I recommend a Web Service to gather the data. The display app can also use the Web Service or query the database directly. I (and several others here) dislike DataAdapters, DataSets, and DataGridViews. I recommend using a DataReader directly and a TreeView. Don't put data access code directly in your GUI code; write a Data Access Layer. Don't use concatenation to form your SQL statements; use parameters.

              R 1 Reply Last reply
              0
              • P PIEBALDconsult

                I hope you're not expecting to have one app that does both the gathering and the displaying. I recommend a Web Service to gather the data. The display app can also use the Web Service or query the database directly. I (and several others here) dislike DataAdapters, DataSets, and DataGridViews. I recommend using a DataReader directly and a TreeView. Don't put data access code directly in your GUI code; write a Data Access Layer. Don't use concatenation to form your SQL statements; use parameters.

                R Offline
                R Offline
                Ronenb
                wrote on last edited by
                #7

                thanks for the tips the apps should be run localy, can i stll run web service, the service should collect the data and insert to db? i'm think of using several threads in te App (one handling the data recieving, one for processing and store in DB, and one for displaying thanks ronen

                P 1 Reply Last reply
                0
                • R Ronenb

                  thanks for the tips the apps should be run localy, can i stll run web service, the service should collect the data and insert to db? i'm think of using several threads in te App (one handling the data recieving, one for processing and store in DB, and one for displaying thanks ronen

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #8

                  Ronenb wrote:

                  can i stll run web service

                  Yes.

                  Ronenb wrote:

                  the service should collect the data and insert to db?

                  Yes.

                  Ronenb wrote:

                  several threads

                  Yes.

                  Ronenb wrote:

                  one handling the data recieving

                  Querying from DB or Service

                  Ronenb wrote:

                  one for processing and store in DB

                  No. That's done by the Service.

                  Ronenb wrote:

                  one for displaying

                  That's the app's main thread. By having a separate process for collecting and storing the data, you can have multiple clients displaying the data.

                  R 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Ronenb wrote:

                    can i stll run web service

                    Yes.

                    Ronenb wrote:

                    the service should collect the data and insert to db?

                    Yes.

                    Ronenb wrote:

                    several threads

                    Yes.

                    Ronenb wrote:

                    one handling the data recieving

                    Querying from DB or Service

                    Ronenb wrote:

                    one for processing and store in DB

                    No. That's done by the Service.

                    Ronenb wrote:

                    one for displaying

                    That's the app's main thread. By having a separate process for collecting and storing the data, you can have multiple clients displaying the data.

                    R Offline
                    R Offline
                    Ronenb
                    wrote on last edited by
                    #9

                    thank you very much for your input

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups