另外,在一个新表中插入行,不能直接用DataTable.Rows.Add(DataRow)的方式,因为这样是插入一个新表,也就是DataRow是 空的。要用导入行的方式,DataTable.ImportRow(DataRow)。当然,前提是这个新表要有与原数据表一样的结构。 1Public Function SDEResearch(ByVal InputDT As DataTable, ByVal SearchStr As String) As DataTable 2 3 '用来存储 再查询后的数据表 4 Dim ReSearchDT As DataTable = InputDT.Clone() '保证有与源数据表相同的表结构 5 6 '用来存储查询后返回的datarow数组 7 Dim ReSearchDR() As DataRow = Nothing 8 9 Try 10 ReSearchDR = InputDT.Select("NAME LIKE '%" + SearchStr + "%'") '只是从数据表中映射出来datarow(),所以不能删除原表中的行 11 Catch ex As Exception 12 Return Nothing 13 End Try 14 15 For i As Int16 = 0 To ReSearchDR.Length - 1 16 ReSearchDT.ImportRow(ReSearchDR(i)) 17 Next 18 19 Return ReSearchDT 20 End Function