jeudi 4 juin 2015

Subtract two data tables into one using one row to subtract with

I'm trying to work off this Example where it shows how to merge one data table with another. My issue is that one data table is one row of baseline values that must be subtracted from each row of raw data and placed in another baseline offset data table. The baseline data table doesn't have a date column but the other two do. I realize I used the join function with Date columns (which is wrong), but I'm unfamiliar when the columns are not equal.

The data tables look like the following

Raw Data

Date____| A | B

12/29/14| 5.5 | 5.8

12/30/14| 5.4 | 5.6

Baseline

A | B

5.0| 5.3

Baseline Offset

Date____ | A | B

12/29/14 | 0.5 | 0.5

12/30/14 | 0.4 | 0.3

 try
            {
                con.Open();

                System.Data.DataTable dtData = new System.Data.DataTable();
                System.Data.DataTable dtBaseline = new System.Data.DataTable();

                var dtBaseline_Offset = from p in dtData.AsEnumerable() 
                                        join q in dtBaseline.AsEnumerable() on p.Field<string>("Date") equals q.Field<string>("Date") into UP
                                        from q in UP.DefaultIfEmpty()
                                        select new
                                        {
                                            date = p.Field<string>("Date"),
                                            MeasA = p.Field<float>("A") - q.Field<float>("A"),
                                            MeasB = p.Field<float>("B") - q.Field<float>("B")
                                        };



                string stringsql1command = "SELECT * from Baseline_Offset";
                string stringsql2command = "SELECT * from Baseline";

                SQLiteDataAdapter sda1 = new SQLiteDataAdapter(stringsql1command, con);
                SQLiteDataAdapter sda2 = new SQLiteDataAdapter(stringsql2command, con);

                System.Data.DataTable dt3 = new System.Data.DataTable();

                sda1.Fill(dt3);

                Baseline_OffsetDataGridView.DataSource = dt3;

Aucun commentaire:

Enregistrer un commentaire