我正在将数据表内容转换为字符串,假设数据集有 12 行和 8 列。最后,字典包含 12 行或 96 列。下面的代码有什么问题,如何重置行?
蒂亚。
Dim ds As DataSet = ClsDB.GetDataSet(sql)
If Not ds Is Nothing AndAlso ds.Tables.Count > 0 Then
Dim row As New List(Of KeyValuePair(Of String, String))
Dim dict As New List(Of KeyValuePair(Of Integer, Object))
Dim dt As DataTable = ds.Tables(0)
Dim i As Integer = 0
For Each dr As DataRow In dt.Rows
For Each dc As DataColumn In dt.Columns
row.Add(New KeyValuePair(Of String, String)(dc.ColumnName, IIf(Not IsDBNull(dr.Item(dc.ColumnName)), dr.Item(dc.ColumnName), "")))
Next
dict.Add(New KeyValuePair(Of Integer, Object)(i, row))
i += i
Next
Return New JavaScriptSerializer().Serialize(dict)
Else
Return "No Data"
End If