from the Chemicals table where Inventory is null. These last rows you could
Inventory amount and date. The dataAdapter's Insert command would then look
"ccshine via DotNetMonster.com" wrote:
> After searching throughout this and other sites trying variations on my code
> to no avail, I confess. I was the second gunman on the grassy knoll! And my
> eyes are about to bug out of my head trying to find a solution to this issue
> so any help would be greatly appreciated.
>
> I have a datagrid that displays info from 2 tables. The setup is quite
> simple - chemicals contains the PK of chemicalID which is related to the
> dailyInventory table FK chemicalID. In my first pass at displaying this data
> I used a JOIN statement. When I finally got it to display the way I wanted,
> I ran into issues trying to update with the OLEDBAdapter. After some soul-
> searching and prescription meds I learned that Join statements should be
> abandoned and instead use a datarelation. Oh boy! Sounds like a piece of
> cake!
>
> I made all the adjustments needed - created OleDBAdapters for all 4 tables,
> populated the dataset and created the relation. Now for the fun part.
> Binding the datagrid to the relation so I can display the "description"
> column from the chemicals table with my data from the dailyInventory table.
> You'll note that I have commented out a few lines trying different options
> based on info from various boards, but I can not get it to work. While it
> isn't throwing any errors, I can only get the info from dailyInventory to
> display. Oh yeah, I can also make nothing display, but I don't find this
> extremely helpful.
>
> In addition to getting the "description" field to display with
> dailyInventory, I need to do a RowFilter based upon date. AND if there are
> no entries for a particular date then I grab the chemical table and loop
> through it to add the description to the datagrid to simplify data entry as
> well. However all I really care about at this point is getting that damn
> description in there. I'm fairly new to .NET so if the mistake is painfully
> obvious....
>
> string strFilter;
>
> // chemicals table
> this.oleAdpChemicals.SelectCommand = this.oleCmdChemicals;
> oleAdpChemicals.Fill(dsChemicalTracking, "chemicals");
> dvChemicals = dsChemicalTracking.Tables["chemicals"].DefaultView;
>
> // dailyInventory table and dataview
> this.oleAdpDailyInv.SelectCommand = this.oleCmdDailyInv;
> oleAdpDailyInv.Fill(dsChemicalTracking, "dailyInventory");
> dvDailyInv = dsChemicalTracking.Tables["dailyInventory"].DefaultView;
> strFilter = "date='" + dtpDate.Value.ToShortDateString() + "'";
> dvDailyInv.RowFilter = strFilter;
>
> // production table
> this.oleAdpProduction.SelectCommand = this.oleCmdProduction;
> oleAdpProduction.Fill(dsChemicalTracking, "production");
>
> // receiving table
> this.oleAdpReceiving.SelectCommand = this.oleCmdReceiving;
> oleAdpReceiving.Fill(dsChemicalTracking, "chemicalsReceived");
>
> // add relations
> DataRelation chemicalsToDailyInv = new DataRelation("chemicalsToDailyInv",
> dsChemicalTracking.Tables["chemicals"].Columns["chemicalID"],
> dsChemicalTracking.Tables["dailyInventory"].Columns["chemicalID"]);
> dsChemicalTracking.Relations.Add(chemicalsToDailyInv);
>
>
> dgDailyInv.DataSource = dvDailyInv;
> dgDailyInv.DataMember = "dailyInventory";
>
> //dgDailyInv.SetDataBinding(dsChemicalTracking, "chemicals.
> chemicalsToDailyInv");
>
>
> // Declare DataGridTableStyle
> // tsDailyInv.MappingName = dsChemicalTracking.Relations
> ["chemicalsToDailyInv"].RelationName;
> //tsDailyInv.MappingName = dsChemicalTracking.Tables["dailyInventory"].
> TableName;
> tsDailyInv.MappingName = dsChemicalTracking.Tables["dailyInventory"].
> TableName;
>
> tsDailyInv.AlternatingBackColor = Color.FromArgb(255, 153, 102);
>
>
> tcDate.MappingName = "date";
> tcDate.HeaderText = "Date";
> tcDate.Width = 100;
> tcDescription.MappingName = "chemicals.description";
> tcDescription.HeaderText = "Chemical";
> tcDescription.Width = 125;
> tcAmtInStock.MappingName = "amtInStock";
> tcAmtInStock.HeaderText = "Amt In Stock";
> tcAmtInStock.Width = 100;
>
> tsDailyInv.GridColumnStyles.Add(tcDate);
> tsDailyInv.GridColumnStyles.Add(tcDescription);
> tsDailyInv.GridColumnStyles.Add(tcAmtInStock);
>
> // Add the DataGridTableStyle instance to the GridTableStylesCollection
> dgDailyInv.TableStyles.Add(tsDailyInv);
> dgDailyInv.Expand(-1);
>
> // get chemical names for dailyInventory entry
> //if (dvDailyInv.Count.Equals(0))
> //{
> // strFilter = "discontinued = 0";
> // dvChemicals.RowFilter = strFilter;
>
> // foreach (DataRowView drChemicals in dvChemicals)
> // {
>
> //drDailyInv = dvDailyInv.AddNew();
> //drDailyInv["date"] = dtpDate.Value.ToShortDateString();
> //drDailyInv["description"] = drChemicals["description"];
> //drDailyInv["amtInStock"] = 0;
> //drDailyInv.EndEdit();
> // }
> //}
>
> --
> Message posted via DotNetMonster.com
>
http://www.dotnetmonster.com/Uwe/Forums.aspx/winform-data-binding/200605/1