I am currently learning the C# .NET programming language and I wanted to throw out some general questions. Your feedback is extremely important to my learning process.
In developing applications that access SQL back-ends there are a million ways to accomplish the same task and I am trying to develop my own standards and methods for my own sanity :-) - I will start with an easy one and hopefully drill down.
Lets say I am reading a table to be displayed in a datagridview. If I need a column in the grid for calculations on each row what is the best approach to populating the grid? Do I:
- create the column in the DATATABLE for the calculations, loop through the table after the .fill to populate the calculated field?
- create the column in the DATAGRIDVIEW for the calculations, loop the table after the .fill to populate the caclulated field?
Thanks for all your help as I plan on residing in these forums for an extended period! Cheers!
Sam HobbsPosted Oct 15, 2010, 6:16 PM
Also, look in this web site for articles about Data Entities; I think there are articles in this web site about that and I know that Visual Studio 2010 has support for that but I have not learned about them either.
I hope at least some of this gets you going in a good direction.
theLizardPosted Oct 15, 2010, 6:03 PM
In a nice way, since you are an SQL expert, have you had any dealings with SQLite version 3.7.x , if so do you know the format for multiple insert statements in a single transaction. It is supposed to be something like
"BEGIN insert into table (...) values( .. ); insert (...) values( .. ); insert (...) values( .. ); insert (...) values( .. ); COMMIT" but this does not workusing SqlExecDirect(... ) through it's ODBC driver, single statements work fine but when you are importing in excess of 4000 records at a time.
P.S. I only use use C# for web sites, everything else is C++ Builder.
Shawn SimmonsPosted Oct 15, 2010, 5:44 PM
Shawn SimmonsPosted Oct 15, 2010, 5:38 PM
I know what you are getting at and I appreciate the insight. I am a SQL expert so the SQL part of this equation is not an issue for me. I am more interested in methods for presenting and updating the data using the .NET framework and determining the best (most accepted) methods are for doing so. This line of questioning is more general in nature. Cheers!
Shawn
theLizardPosted Oct 15, 2010, 5:29 PM
Just for example.
sqlQuery = "SELECT table1.name, table1.street, SUM(table2.Total) as total FROM table1, table2 INNER JOIN table 2 ON table2.nameId = table1.id"
as i said this is just for example, you could also select into a new table the result set of your query.
As you said there are a million ways to accomplish the task.
Sam HobbsPosted Oct 15, 2010, 4:52 PM
The first thing to do is to look at the articles in this web site. I think one that could especially useful is my Database Table Update in a DataGridView without Writing Code. That article will at least introduce the concept of "bound" forms. I think it is relatively easy to add a column to a DataGridView bound to a table such that the additional column can be calculated. An alternative would be to create a TableAdapter using SQL that calculates an additional column; I am not sure of the details of doing that but it is possible.
I suggest that for you should learn to avoid using controls (such as the DataGridView) as the container; in other words, do not store the data in the control for the purposes of processing the data. Use controls for the UI; that is, to show the data. Learn about use of bound controls, such as in my article. The requirement of a calculated column is a complication, but it can be solved a few ways at least. One way would be similar to your idea of creating a DataTable. I think you can use the Database Designer to create a DataTable that consists of the fields in the table in the database plus additional column(s) and you could copy the database table to the temporary DataTable and then calculate the additional column(s).
If you really want to learn the right way to do things from the beginning, learn about use of a Data Access Layer (DAL) and Business Logic Layer (BLL). There is also a presentation layer but I forget what it is called. I have not looked at that but I intend to.