Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > sql query on database tables
 

sql query on database tables


Hi Adland,

Thanks for response.

---------------------


Before we go any further, could you please answer the questions below:


1. How would use do the calculations, writing sql script or operating on a DataSet programmatically?

The calculation would be displayed within the web form, so they will need to be written back to the same table. So, more than likely writing a sql script


2. What is the structure of the three tables?

The fields within the tables that needs to be calculated are in the "Decimal" (18,0)format


3. Could you provide the formular of the calculations in detail?

I give you an example of the formula?

Table A

FieldA,

Field B,

Field C,

Field D,

Field E

The sum of the formulaof Table A is displayed in Field E (Field A + Field C + Field D)

TableB

FieldA,

Field B,

Field C,

Field D,

Field E

The sum of the formulaof TableB is displayed in Field E (Field A + FieldB + Field C - Field D)

TableC

FieldA (populated from Field E from table A)

Field B,

Field C (populated from Field E from table B

Field D,

Field E

The sum of the formulaof TableC is displayed in Field E (Field A + FieldB- Field C+ Field D)


In general order for my web forms to work, they rely on cross data population from other tables. In the example above, only Table C uses cross data population.

I can only guess that if I’m trying to calculate an equation, them I will need to add the table name for each field in Table C. I'm most probably wrong on this, as I'm a complete novice.


I would like to use SQL script to perform the calculations. However, if you could explain how it could be done I Datasets as well, I would be truly grateful.


Your help is much welcome


--------------------------------------------------
-----------
Hi

I have three web forms created in VWD that are linked to a an sql database with three tables (Table A, Table B and Table C).

Each table has a number decimal field types.

I need to calculate some but not all decimal fields in table A;

I also need to calculate totals in some but not all decimal fields in table B;

Table C needs to populate the totalsfrom table A and B, also calculating totals withinthe sametable (Table C). I also need to subtract some values as well in cetain places.

Can someone please help me out or at least point me to a webpage that can help me out
phillonc  Thursday, September 03, 2009 10:57 AM
You should probably visit a T-SQL forum to get a more honed reponse.

Is this data cached in a DataSet?
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
JohnGrove  Thursday, September 03, 2009 10:33 PM
Hi phillonc,

Before we go any further, could you please answer the questions below:
1. How would use do the calculations, writing sql script or operating on a DataSet programmatically?
2. What is the structures of the three tables?
3. Could you provide the formular of the calculations in detail?

These are some of my ideas:
1. Calculate the sum of field col1 in table A.
sql: select sum(col1) from A.
code: dataTable.Compute("sum(col1)", "1=1");
2. Calculate the sum of fields col1,col2to a new field col_sum.
sql: select col_sum = col1 + col2
code: dataTable.Columns["col_sum"].Expression = "col1 + col2";

We can get more information about sql aggregate functions from:
http://msdn.microsoft.com/en-us/library/ms173454.aspx
We can get more information about the Compute method and the Expression property from:
http://msdn.microsoft.com/en-us/library/system.data.datatable.compute.aspx
http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression(VS.71).aspx

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, September 07, 2009 5:55 AM

Hi,

We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, September 11, 2009 2:09 AM

You can use google to search for other answers

Custom Search

More Threads

• more on binding name/value
• running a stored procedure with multiple select statments by the adapter
• visual c++ to c#
• List View row height....
• disable highlights when selecting
• What is the best way when user select row in dataGridView to display data in TextBoxes?
• what did I do wrong while passing dateTimePicker value to bindingSource filter?
• Convert datagridview data to temp table
• [resend] Controls for editing multi-value, multi-row fields
• DataGridViewComboBoxColumn problem