C# DSHelper and Datatables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DragonLord
    New Member
    • Mar 2007
    • 122

    C# DSHelper and Datatables

    Hi guys I am using a for loop to add rows to a datatable after i scan an item. and that item has to be added x number of times.

    The problem is that I am using DSHelper to group by one of the fields and if I do two scans one with 11 and one with 22 as the quantity instead of giving me 1 row with a count of 33 it gives me two rows one with 22 grouped together and one with 11 grouped together matching the original datatable.

    Here is the for loop.....

    Code:
    for (int i = 0; i < intAddQuantity; i++)
    			{
    				DataRow objDR = objDataTable.NewRow();
    				//The following code adds the data to the table.
    				objDR["Quantity"] = "1";
    				objDR["Barcode"] = strScanText;
    				objDR["Destination"] = strDestination;
    				objDR["TimeStamp"] = DateTime.Now;
    				objDR["Manual"] = false;
     
    				objDataTable.Rows.Add(objDR);
    				dataGridViewScan.DataSource = objDataTable;
    				//Adjust the column widths as required.
    				dataGridViewScan.Columns["Barcode"].Width = 200;
    				dataGridViewScan.Columns["TimeSTamp"].Width = 175;
    				dataGridViewScan.Columns["Destination"].Width = 300;
     
    			}
    				dataGridViewScan.Refresh();
    				//Clear fields
    				textBoxScan.Text = "";
    				textBoxInvoiceNumber.Text = "";
    				textBoxRowCount.Text = objDataTable.Rows.Count.ToString();
    I will answer any questions you want if you can offer any help why the grouping is based on the orginal additions i would appreciate the help.
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    Which field do you group it by?
    is there a difference between adding the quatinty as 22 and then 11 ?

    As you confirmed that rows are being added to the database, there is clearly a difference when u add the item with quantity 22 and then as 11.

    Comment

    • DragonLord
      New Member
      • Mar 2007
      • 122

      #3
      I am grouping on the destination address, which is just pulled from a text box exactly the same way.

      What I am doing is basically creating a scanning app that will merge any orders going to a specific destination address. (the text box) So on the keypress event it captures the enter key from the scanner and calls a form to get the quantity. I put in the quantity and it adds them to one datagridview which has it's datasource pointing to the datatable in the for loop.

      Then I scan the same barcode again leaving the address exactly the same and again it goes through the for loop with the next batch of orders.

      The purpose of this is that the first datagridview shows single items i.e. if there are 20 items scanned of the same product there will be 20 lines of quantity one.

      Later I need to merge all these lines into another table with only total piece counts for all common destinations.

      It sorta works except what happens is that it seems to group in the same way i scanned in. If i scanned 33 then 12 then 2 items when it groups it comes out exactly the same it takes all the single items and groups them again into 33 , 12 and 2 instead of 47.. now I walked through the code for the DSHelper and it passes the table with 47 total records but I can't figure out where it is somehow thinking that the groups are not the same because the data appears to be exactly the same from my trace feild on destination..


      I am really confused as to what it is seeing as different ....

      Comment

      • DragonLord
        New Member
        • Mar 2007
        • 122

        #4
        here is my code that calls the DSHelper functions In case this is where the error is.

        Code:
         {
        			FieldList = "count(Destination) Quantity,Barcode,Destination,max(TimeStamp) TimeStamp,Manual";
        			GroupbyList = "Destination";
        			dsHelper = new DataSetHelper.DataSetHelper(ref DSscan);
        			//dsHelper.CreateGroupByTable("ScanDetailsMerge", DS.Tables["ScanDetails"],FieldList);
        			//dsHelper.InsertGroupByInto(DS.Tables["ScanDetailsMerge"], DS.Tables["ScanDetails"], FieldList, "", GroupbyList);
        			dsHelper.CreateGroupByTable("ScanDetailsMerge", objDataTable, FieldList);
        			dsHelper.InsertGroupByInto(DSscan.Tables["ScanDetailsMerge"], objDataTable, FieldList, "", GroupbyList);
        			dataGridView1.DataMember = "ScanDetailsMerge";
        			dataGridView1.DataSource = DSscan.Tables["ScanDetailsMerge"];
        		}

        Comment

        • DragonLord
          New Member
          • Mar 2007
          • 122

          #5
          Any one at all? I really need to be able to do this without it grouping by the original looped row entries.



          Thanks in advance.

          Comment

          • DragonLord
            New Member
            • Mar 2007
            • 122

            #6
            Ok i see something happening and i am not sure why it is happening.

            I am passing the dataset to the insert group function and for some reason every second set of data has a /r/n in front of the grouping field.

            I have been through my code and i have tried to illiminate this any thoughts would be welcome.

            Comment

            Working...