dtOrdDetails被声明为Public DataTable Sub是: Dim stFilter as String Dim OrdersRows()as DataRow ''如果OrderNo =""然后订单是ASN 如果gstOrderNo =""然后 ''ASN选择 否则 ''OrderNo选择 ''为dtOrderDetails创建结构 dtOrderDetails = dsPOs.Tables(" PODetails") dtOrderDetails.Clear() ''设置过滤器 - 列[PONo] =选择的订单号 stFilter =" PONo =" &安培; gstOrderNo OrdersRows = dsPOs.Tables(" PODetails")。选择(stFilter) ''填充dtOrderDetails For i = 0到OrdersRows.GetUpperBound(0) dtOrderDetails.ImportRow(OrderRows(i)) 下一个我 结束如果 我的问题是OrderRows的行数为0但我可以在那里看到有效的 记录。 I还试过: stFilter =" PONo =''" &安培; gstOrderNo& "''" stFilter =" PONO =" &安培; gstOrderNo stFilter =" PONO =" &安培; gstOrderNo& "''" 实际别名字段名称是PONo但我注意到DB2数据库返回 列大写。 字段类型是十进制8,0 我可以单步执行DataTablePODetails并且可以看到PONo =所选的 过滤编号。 感谢您的帮助, Doug 解决方案 道格, 你有什么理由不使用currencymanager.position 起点并使用数据网格中的底层表格来完成新数据表的 填充,直到达到要执行的行为止? Cor " Doug Bell" < dug @ bigpond> .. 我在尝试从选择创建(临时)DataTable时遇到问题一个DataGrid(dgOrders)。 dtOrdDetails被声明为Public DataTable Dim stFilter as String Dim OrdersRows ()as DataRow ''如果OrderNo =""然后订单是ASN 如果gstOrderNo =""然后''ASN选择 其他''OrderNo Selection ''为dtOrderDetails创建结构 dtOrderDetails = dsPOs.Tables( PODetails) dtOrderDetails.Clear() ''设置过滤器 - 列[PONo] =选择的订单号 stFilter =" PONo =" &安培; gstOrderNo OrdersRows = dsPOs.Tables(" PODetails")。选择(stFilter) ''填充dtOrderDetails 对于i = 0到OrdersRows.GetUpperBound(0) dtOrderDetails.ImportRow(OrderRows(i))接下来我 结束如果 我的问题是OrderRows的行数为0但我可以那里看到有效的记录。我也尝试过: stFilter =" PONo =''" &安培; gstOrderNo& "''" stFilter =" PONO =" &安培; gstOrderNo stFilter =" PONO =" &安培; gstOrderNo& "''" 实际别名字段名称是PONo,但我注意到DB2数据库返回列大写。字段类型是十进制8,0 我可以逐步浏览DataTablePODetails。并且可以看到PONO = 选择的过滤器编号。 感谢您的帮助, Doug Doug,我的问题是OrderRows的行数为0,但我可以在那里看到有效的记录。 dtOrderDetails = dsPOs.Tables(" PODetails") dtOrderDetails.Clear()您刚刚清除了dsPOs.Tables(" PODetails")! DataTable是一种引用类型,当您将一个引用 变量/属性分配给另一个时,您正在制作该引用的副本。 变量(dtOrderDetails& dsPOs.Tables(" PODetails"))指的是堆上的确切 相同的DataTable对象。如果您在一个变量上调用Clear,那么 也会在另一个变量上调用clear。 而不是上面两行,您可以使用以下内容单行: dtOrderDetails = dsPOs.Tables(" PODetails")。Clone() 这会创建DataTable结构的空副本。如果您使用 ..Copy()(如您在前面的帖子中提到的那样),您将获得结构 &您的DataTable的数据。 您的其余代码应该可以使用。我通常使用For Each代替 For,主要是为了避免off by one。问题,但这不应该导致你的代码有问题。 对于OrdersRows中的每行作为DataRow dtOrderDetails。 ImportRow(行) 下一页我 希望这有帮助 Jay 道格贝尔 <挖@的BigPond>在消息中写道 新闻:%2 **************** @ TK2MSFTNGP14.phx.gbl ...我遇到了问题尝试从DataGrid(dgOrders)的选择创建一个(临时)DataTable。 dtOrdDetails被声明为Public DataTable Sub是:将OrdersRows()调暗为DataRow ''如果OrderNo =""然后订单是ASN 如果gstOrderNo =""然后''ASN选择 其他''OrderNo Selection ''为dtOrderDetails创建结构 dtOrderDetails = dsPOs.Tables( PODetails) dtOrderDetails.Clear() ''设置过滤器 - 列[PONo] =选择的订单号 stFilter =" PONo =" &安培; gstOrderNo OrdersRows = dsPOs.Tables(" PODetails")。选择(stFilter) ''填充dtOrderDetails 对于i = 0到OrdersRows.GetUpperBound(0) dtOrderDetails.ImportRow(OrderRows(i))接下来我 结束如果 我的问题是OrderRows的行数为0但我可以那里看到有效的记录。我也尝试过: stFilter =" PONo =''" &安培; gstOrderNo& "''" stFilter =" PONO =" &安培; gstOrderNo stFilter =" PONO =" &安培; gstOrderNo& "''" 实际别名字段名称是PONo,但我注意到DB2数据库返回列大写。字段类型是十进制8,0 我可以逐步浏览DataTablePODetails。并且可以看到PONO = 选择的过滤器编号。 感谢您的帮助, Doug 面团, 我从周杰伦的消息中得知我在下面做的是什么 你想做什么 \\\这个样本需要一个包含2个datagrids的表单 Private Sub Form1_Load(ByVal sender As Object,_ ByVal e As System.EventArgs)处理MyBase.Load DataGrid1.DataSource = createDS.Tables(0) Dim mynewtable As DataTable = _ DirectCast(DataGrid1.DataSource,DataTable).Clone Dim myrows As DataRow()= DirectCast(DataGrid1.DataSource,_ DataTable )。选择(" Numbers> 5") For each dr As DataRow in myrows mynewtable.ImportRow(dr) Next DataGrid2.DataSource = mynewtable End Sub ''Bellow仅用于在数据中创建数据表et b / b Public Function createDS()As DataSet Dim ds As New DataSet Dim dt As New DataTable ds.Tables.Add(dt) dt.Columns.Add(" Numbers",GetType(System.Int32)) dt.Columns.Add("字符) 对于i as Integer = 0到10 ds.Tables(0).Rows.Add(ds.Tables(0).NewRow) ds.Tables(0).Rows(i).ItemArray = _ (新对象(){i.ToString,ChrW(i + 65)}) 下一页 返回ds 结束功能 /// 我希望这有帮助吗? Cor " Doug Bell" < dug @ bigpond> .. 我在尝试从选择创建(临时)DataTable时遇到问题一个DataGrid(dgOrders)。 dtOrdDetails被声明为Public DataTable Dim stFilter as String Dim OrdersRows ()as DataRow ''如果OrderNo =""然后订单是ASN 如果gstOrderNo =""然后''ASN选择 其他''OrderNo Selection ''为dtOrderDetails创建结构 dtOrderDetails = dsPOs.Tables( PODetails) dtOrderDetails.Clear() ''设置过滤器 - 列[PONo] =选择的订单号 stFilter =" PONo =" &安培; gstOrderNo OrdersRows = dsPOs.Tables(" PODetails")。选择(stFilter) ''填充dtOrderDetails 对于i = 0到OrdersRows.GetUpperBound(0) dtOrderDetails.ImportRow(OrderRows(i))接下来我 结束如果 我的问题是OrderRows的行数为0但我可以那里看到有效的记录。我也尝试过: stFilter =" PONo =''" &安培; gstOrderNo& "''" stFilter =" PONO =" &安培; gstOrderNo stFilter =" PONO =" &安培; gstOrderNo& "''" 实际别名字段名称是PONo,但我注意到DB2数据库返回列大写。字段类型是十进制8,0 我可以逐步浏览DataTablePODetails。并且可以看到PONO = 选择的过滤器编号。 感谢您的帮助, Doug Hi,I am having problems trying to create a (temporary) DataTable from aselection from a DataGrid (dgOrders).dtOrdDetails is declared as a Public DataTableSub is:Dim stFilter as StringDim OrdersRows() as DataRow''If OrderNo = "" then Order is an ASNIf gstOrderNo = "" Then''ASN SelectionElse''OrderNo Selection''Create structure for dtOrderDetailsdtOrderDetails = dsPOs.Tables("PODetails")dtOrderDetails.Clear()''Set Filter - Column [PONo] = Selected Order No.stFilter = "PONo = " & gstOrderNoOrdersRows = dsPOs.Tables("PODetails").Select(stFilter)''Populate dtOrderDetailsFor i = 0 to OrdersRows.GetUpperBound(0)dtOrderDetails.ImportRow(OrderRows(i))Next iEnd IfMy problem is that OrderRows has a Row Count of 0 and yet I can see validrecords there.I have also tried:stFilter = "PONo = ''" & gstOrderNo & "''"stFilter = "PONO = " & gstOrderNostFilter = "PONO = " & gstOrderNo & "''"Actual Alias Field Name is PONo but I have noticed the DB2 Database returnsColumns capitalised.Field Type is Decimal 8,0I can step through the DataTable "PODetails" and can see PONo = the SelectedFilter Number.Thanks for any help,Doug 解决方案 Doug,Is there any reason that don''t you use the currencymanager.position for yourstart point and use the underlaying table from the datagrid to do thefilling of your new datatable until the rows to do are reached?Cor"Doug Bell" <dug@bigpond>.. Hi, I am having problems trying to create a (temporary) DataTable from a selection from a DataGrid (dgOrders). dtOrdDetails is declared as a Public DataTable Sub is: Dim stFilter as String Dim OrdersRows() as DataRow ''If OrderNo = "" then Order is an ASN If gstOrderNo = "" Then ''ASN Selection Else ''OrderNo Selection ''Create structure for dtOrderDetails dtOrderDetails = dsPOs.Tables("PODetails") dtOrderDetails.Clear() ''Set Filter - Column [PONo] = Selected Order No. stFilter = "PONo = " & gstOrderNo OrdersRows = dsPOs.Tables("PODetails").Select(stFilter) ''Populate dtOrderDetails For i = 0 to OrdersRows.GetUpperBound(0) dtOrderDetails.ImportRow(OrderRows(i)) Next i End If My problem is that OrderRows has a Row Count of 0 and yet I can see valid records there. I have also tried: stFilter = "PONo = ''" & gstOrderNo & "''" stFilter = "PONO = " & gstOrderNo stFilter = "PONO = " & gstOrderNo & "''" Actual Alias Field Name is PONo but I have noticed the DB2 Database returns Columns capitalised. Field Type is Decimal 8,0 I can step through the DataTable "PODetails" and can see PONo = the Selected Filter Number. Thanks for any help, DougDoug, My problem is that OrderRows has a Row Count of 0 and yet I can see valid records there. dtOrderDetails = dsPOs.Tables("PODetails") dtOrderDetails.Clear()You just cleared dsPOs.Tables("PODetails")!DataTable is a reference type, when you assign one referencevariable/property to another you are making a copy of the reference. Bothvariables (dtOrderDetails & dsPOs.Tables("PODetails")) refer to the exactsame DataTable object on the heap. If you call Clear on the one variable youare also calling clear on the other variable.Instead of the above two lines, you can use the following single line: dtOrderDetails = dsPOs.Tables("PODetails").Clone()This creates an empty copy of the structure of your DataTable. If you used..Copy() (as Cor mentioned in your earlier post) you would get the structure& data of your DataTable.The rest of your code should work. I normally use a For Each instead of aFor, mostly to avoid "off by one" problems, however that should not cause aproblem with your code.For Each row As DataRow in OrdersRowsdtOrderDetails.ImportRow(row)Next iHope this helpsJay"Doug Bell" <dug@bigpond> wrote in messagenews:%2****************@TK2MSFTNGP14.phx.gbl... Hi, I am having problems trying to create a (temporary) DataTable from a selection from a DataGrid (dgOrders). dtOrdDetails is declared as a Public DataTable Sub is: Dim stFilter as String Dim OrdersRows() as DataRow ''If OrderNo = "" then Order is an ASN If gstOrderNo = "" Then ''ASN Selection Else ''OrderNo Selection ''Create structure for dtOrderDetails dtOrderDetails = dsPOs.Tables("PODetails") dtOrderDetails.Clear() ''Set Filter - Column [PONo] = Selected Order No. stFilter = "PONo = " & gstOrderNo OrdersRows = dsPOs.Tables("PODetails").Select(stFilter) ''Populate dtOrderDetails For i = 0 to OrdersRows.GetUpperBound(0) dtOrderDetails.ImportRow(OrderRows(i)) Next i End If My problem is that OrderRows has a Row Count of 0 and yet I can see valid records there. I have also tried: stFilter = "PONo = ''" & gstOrderNo & "''" stFilter = "PONO = " & gstOrderNo stFilter = "PONO = " & gstOrderNo & "''" Actual Alias Field Name is PONo but I have noticed the DB2 Database returns Columns capitalised. Field Type is Decimal 8,0 I can step through the DataTable "PODetails" and can see PONo = the Selected Filter Number. Thanks for any help, DougDough,I get from the message from Jay the idea that what I did below is somethingas you wanted to do\\\This sample needs a form with 2 datagridsPrivate Sub Form1_Load(ByVal sender As Object, _ByVal e As System.EventArgs) Handles MyBase.LoadDataGrid1.DataSource = createDS.Tables(0)Dim mynewtable As DataTable = _DirectCast(DataGrid1.DataSource, DataTable).CloneDim myrows As DataRow() = DirectCast(DataGrid1.DataSource, _DataTable).Select("Numbers > 5")For Each dr As DataRow In myrowsmynewtable.ImportRow(dr)NextDataGrid2.DataSource = mynewtableEnd Sub''Bellow only to create a datatable in a datasetPublic Function createDS() As DataSetDim ds As New DataSetDim dt As New DataTableds.Tables.Add(dt)dt.Columns.Add("Numbers", GetType(System.Int32))dt.Columns.Add("Characters")For i As Integer = 0 To 10ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)ds.Tables(0).Rows(i).ItemArray = _(New Object() {i.ToString, ChrW(i + 65)})NextReturn dsEnd Function///I hope this helps?Cor"Doug Bell" <dug@bigpond>.. Hi, I am having problems trying to create a (temporary) DataTable from a selection from a DataGrid (dgOrders). dtOrdDetails is declared as a Public DataTable Sub is: Dim stFilter as String Dim OrdersRows() as DataRow ''If OrderNo = "" then Order is an ASN If gstOrderNo = "" Then ''ASN Selection Else ''OrderNo Selection ''Create structure for dtOrderDetails dtOrderDetails = dsPOs.Tables("PODetails") dtOrderDetails.Clear() ''Set Filter - Column [PONo] = Selected Order No. stFilter = "PONo = " & gstOrderNo OrdersRows = dsPOs.Tables("PODetails").Select(stFilter) ''Populate dtOrderDetails For i = 0 to OrdersRows.GetUpperBound(0) dtOrderDetails.ImportRow(OrderRows(i)) Next i End If My problem is that OrderRows has a Row Count of 0 and yet I can see valid records there. I have also tried: stFilter = "PONo = ''" & gstOrderNo & "''" stFilter = "PONO = " & gstOrderNo stFilter = "PONO = " & gstOrderNo & "''" Actual Alias Field Name is PONo but I have noticed the DB2 Database returns Columns capitalised. Field Type is Decimal 8,0 I can step through the DataTable "PODetails" and can see PONo = the Selected Filter Number. Thanks for any help, Doug 这篇关于从SelectTable中选择创建1DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-11 18:52