code problem? missing an entry when populating grid

manared

Well-known member
Joined
Jun 1, 2006
Messages
84
Programming Experience
1-3
I'm sorry this code is going to be long, but I'm really having problems. I am missing one entry when I do this search. I populate a grid then and I'm always missing just one or two entries. I know they should be there because when I search in SQL management studio, they show up. Do I need to change my code somehow or do it in a different way? Thanks for your help in any way on this.


VB.NET:
 strSQL = "SELECT DISTINCT LookupQuoteIncludeType.IncludeTypeDesc As IncludeType, QuoteForecast.IncludeType, CASE WHEN QuoteMaster.QuoteDate > '1/1/1980' THEN QuoteMaster.QuoteDate ELSE QuoteMaster.CreateDate END AS CreateDate, QuoteMaster.QuoteNumber AS QuoteNo, Customer.CustomerName AS CompanyName, QuoteForecast.Description, QuoteCheckList.SellingAmount AS Amount, Salesperson.FirstName + ' ' + Salesperson.LastName AS Salesperson, LookupSalesRep.Name AS SalesRepresent, LookupQuoteStatus.StatusDesc AS Status, QuoteForecast.RelationshipRating AS Rel, QuoteForecast.BiddingRating AS Bid, QuoteForecast.CommitmentRating AS Com, QuoteForecast.TotalRating AS Total, QuoteForecast.Comments AS CommentsSalesForecast, QuoteMaster.OrderDate, QuoteMaster.RevisedOrderDate AS RevisedDate, QuoteCheckList.EquipmentDeliveryWeeks AS Delivery, QuoteCheckList.SellingMargin AS PerMar, ROUND((QuoteCheckList.SellingMargin/100)*QuoteCheckList.SellingAmount,2) AS DolMar, QuoteMaster.JobSite As JobSite, QuoteMaster.EngHours AS EngHr, QuoteMaster.DraftHours AS DraftHr, QuoteMaster.ShopHours AS ShopHr FROM (LookupQuoteIncludeType INNER JOIN (LookupQuoteStatus INNER JOIN QuoteForecast ON LookupQuoteStatus.StatusID = QuoteForecast.Status) ON LookupQuoteIncludeType.IncludeID = QuoteForecast.IncludeType) INNER JOIN (LookupSalesRep INNER JOIN (Salesperson INNER JOIN ((Customer INNER JOIN QuoteMaster ON Customer.ID = QuoteMaster.BuyerID) INNER JOIN QuoteCheckList ON QuoteMaster.ID = QuoteCheckList.ID) ON Salesperson.ID = QuoteMaster.SalesPersonID) ON LookupSalesRep.ID = QuoteMaster.SalesRepID1) ON QuoteForecast.ID = QuoteMaster.ID WHERE ((QuoteForecast.IncludeType)<>5) ORDER BY QuoteForecast.IncludeType, QuoteForecast.TotalRating DESC" 


            'create new temporary table and sort via dataview object 
            Dim dt As Data.DataTable 
            Dim dr As DataRow 

            '' ''Dim intBlankCounter As Integer 

            'create a DataTable 
            dt = New Data.DataTable() 

            'add the columns for the datatable 
            dt.Columns.Add(New DataColumn("IncludeType", GetType(String))) 
            dt.Columns.Add(New DataColumn("CreateDate", GetType(String))) 
            dt.Columns.Add(New DataColumn("QuoteNo", GetType(String))) 
            dt.Columns.Add(New DataColumn("CompanyName", GetType(String))) 
            dt.Columns.Add(New DataColumn("Description", GetType(String))) 
            dt.Columns.Add(New DataColumn("Amount", GetType(String))) 
            dt.Columns.Add(New DataColumn("Salesperson", GetType(String))) 
            dt.Columns.Add(New DataColumn("SalesRepresent", GetType(String))) 
            dt.Columns.Add(New DataColumn("Status", GetType(String))) 
            dt.Columns.Add(New DataColumn("Rel", GetType(String))) 
            dt.Columns.Add(New DataColumn("Bid", GetType(String))) 
            dt.Columns.Add(New DataColumn("Com", GetType(String))) 
            dt.Columns.Add(New DataColumn("Total", GetType(String))) 
            dt.Columns.Add(New DataColumn("CommentsSalesForecast", GetType(String))) 
            dt.Columns.Add(New DataColumn("OrderDate", GetType(String))) 
            dt.Columns.Add(New DataColumn("RevisedDate", GetType(String))) 
            dt.Columns.Add(New DataColumn("Delivery", GetType(String))) 
            dt.Columns.Add(New DataColumn("PerMar", GetType(String))) 
            dt.Columns.Add(New DataColumn("DolMar", GetType(String))) 
            dt.Columns.Add(New DataColumn("JobSite", GetType(String))) 
            dt.Columns.Add(New DataColumn("EngHr", GetType(String))) 
            dt.Columns.Add(New DataColumn("DraftHr", GetType(String))) 
            dt.Columns.Add(New DataColumn("ShopHr", GetType(String))) 
            dt.Columns.Add(New DataColumn("Eng", GetType(String))) 
            dt.Columns.Add(New DataColumn("Draft", GetType(String))) 
            dt.Columns.Add(New DataColumn("Shop", GetType(String))) 

Dim drForeCast As SqlDataReader 
            Dim drTemp As SqlDataReader 

            Dim cmdForecast As New SqlCommand 
            conn.Open() 
            cmdForecast.Connection = conn 
            cmdForecast.CommandText = strSQL 
            drForeCast = cmdForecast.ExecuteReader 


            Dim cmdTemp As New SqlCommand 
            conn2.Open() 
            cmdTemp.Connection = conn2 
            cmdTemp.CommandText = strSQL 
            drTemp = cmdTemp.ExecuteReader 
            drTemp.Read() 

While drTemp.Read() 
                Dim eng, draft, shop, margin, DolEng, DolDraft, DolShop As Integer 
                Dim num As String = drTemp("QuoteNo") 
margin = drTemp("DolMar") 
eng = drTemp("EngHr") 
                draft = drTemp("DraftHr") 
                shop = drTemp("ShopHr") 
                If eng = 0 Then 
                    DolEng = 0 
                Else 
                    DolEng = margin / eng 
                End If 
                If draft = 0 Then 
                    DolDraft = 0 
                Else 
                    DolDraft = margin / draft 
                End If 
                If shop = 0 Then 
                    DolShop = 0 
                Else 
                    DolShop = margin / shop 
                End If 

dr = dt.NewRow() 

                'calls checkDate function for proper includetype string based on dates and also adds the amount 
                'to global total variables 
                dr(0) = checkDate(drTemp("RevisedDate"), drTemp("OrderDate"), drTemp("IncludeType"), drTemp("Amount"), drTemp("QuoteNo")) 
                dr(1) = drTemp("CreateDate") 
                dr(2) = drTemp("QuoteNo") 
                dr(3) = drTemp("CompanyName") 
                dr(4) = drTemp("Description") 
                dr(5) = drTemp("Amount") 
                dr(6) = drTemp("Salesperson") 
                dr(7) = drTemp("SalesRepresent") 
                dr(8) = drTemp("Status") 
                dr(9) = drTemp("Rel") 
                dr(10) = drTemp("Bid") 
                dr(11) = drTemp("Com") 
                dr(12) = drTemp("Total") 
                dr(13) = drTemp("CommentsSalesForecast") 
                dr(14) = drTemp("OrderDate") 
                dr(15) = drTemp("RevisedDate") 
                dr(16) = drTemp("Delivery") 
                dr(17) = drTemp("PerMar") 
                dr(18) = drTemp("DolMar") 
                dr(19) = drTemp("JobSite") 
                dr(20) = drTemp("EngHr") 
                dr(21) = drTemp("DraftHr") 
                dr(22) = drTemp("ShopHr") 
                dr(23) = DolEng 
                dr(24) = DolDraft 
                dr(25) = DolShop 
                '' ''End If 
                dt.Rows.Add(dr) 
                intCount -= 1 
                intRowCount += 1 
                margin = 0 
                eng = 0 
                draft = 0 
                shop = 0 
                DolEng = 0 
                DolDraft = 0 
                DolShop = 0 

            End While 

drForeCast.Read() 
Session("Source") = dt 
Dim dv As DataView = New DataView(dt) 

            grdSalesForecast.DataSource = dv 
            grdSalesForecast.DataBind() 

            'if all sales then sort the grid 
            If (rdoReport.SelectedValue = "Just Show All") Or ((rdoReport.SelectedValue = "Salesman") And (DropDownList1.SelectedValue = "0")) Then 
                grdSort() 
            End If 
drForeCast.Close() 
            conn2.Close() 
            drTemp.Close() 
            conn.Close()
 
Back
Top