开发者

How to code multiple datasets in VB.NET?

开发者 https://www.devze.com 2023-03-20 05:20 出处:网络
I have a report where I need the same data, but for four separate date ranges.Currently this data is based on one month, so it\'s just one dataset.But now I am trying to do this with four separate dat

I have a report where I need the same data, but for four separate date ranges. Currently this data is based on one month, so it's just one dataset. But now I am trying to do this with four separate datasets, where each one is filtered on each of the four date ranges. I setup my WHILE loop to loop thru all four dates. But I'm having trouble now with distinct naming these datasets. Is this the best way to do this? It looks like if I used multiple datatables for one dataset, I'd have to define each datatable column. Here is my current dataset commandstring:

commandstring = "SELECT Batch_Records.Part_Number, Batch_Records.Lot_Number, Batch_Records.Date_Received, " & _
                                           "IsNull([Date_Completed], [Review_Date]) AS CompleteDate, Batch_Records.Error, " & _
                                           "Batch_Records.[Group], Batch_Records.MFG, Batch_Records.MFG2, Batch_Records.QC, Batch_Records.QC2, " & _
                                           "QC_CODES.CODE_DESC " & _
                                           "FROM EXCEL.Batch_Records LEFT JOIN EXCEL.QC_CODES ON Batch_Records.Part_Number = QC_CODES.CODE_ID " & _
                                           "WHERE (Batch_Records.[Group]" & TheGroup & " 开发者_运维知识库AND Batch_Records.Date_Received > '" & arrWeekYear(i, j).ToString("d") & "' AND Batch_Records.Date_Received < '" & arrWeekYear(i + 7, j).ToString("d") & "')"


If I understand it correctly, you want 4 ranges in one query:

extend the WHERE (and watch out for the brackets...)

"WHERE (Batch_Records.[Group]" & TheGroup & 
" AND (Batch_Records.Date_Received > '" & arrWeekYear(i1, j).ToString("d") & "' AND Batch_Records.Date_Received < '" & arrWeekYear(i1 + 7, j).ToString("d") &
") or (Batch_Records.Date_Received > '" & arrWeekYear(i2, j).ToString("d") & "' AND Batch_Records.Date_Received < '" & arrWeekYear(i2 + 7, j).ToString("d") &
") or (Batch_Records.Date_Received > '" & arrWeekYear(i3, j).ToString("d") & "' AND Batch_Records.Date_Received < '" & arrWeekYear(i3 + 7, j).ToString("d") &
") or (Batch_Records.Date_Received > '" & arrWeekYear(i4, j).ToString("d") & "' AND Batch_Records.Date_Received < '" & arrWeekYear(i4 + 7, j).ToString("d") &
"'))"

Or if you want to have 4 sets of output, create a parameterized query. Run it 4 times just updating the parameter values. Thus you have no naming problems as you have only 1 query.

0

精彩评论

暂无评论...
验证码 换一张
取 消