handle data in GUI (datagridview) and database
-
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
-
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
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."
-
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."
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
-
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
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."
-
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."
-
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
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.
-
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.
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
-
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
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.
-
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.