在vb.net中更改datatable中列的值 [英] changing values of a column in datatable in vb.net
本文介绍了在vb.net中更改datatable中列的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想循环使用数据库,并更改该数据表中特定列的值。
I want to loop through a databale and change the values of a specific column in that datatable.
例如:数据库返回 Request_ID
, Desc
,日期
和 Status_Ind
。 Status_Ind
列包含整数值。我不想向用户显示整数值。我想将它转换为一个字符串值,基于该列返回的整数值。
eg: the database returns Request_ID
, Desc
, Date
and Status_Ind
. The Status_Ind
column contains integer values. I dont want to show the integer values to the user. I want to convert that to a string value based on the integer values returned in that columns.
if Status_Ind = 1 then
'the values changes to Published
推荐答案
您可以它创建另一列:
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("status_int", GetType(Int32)))
dt.Columns.Add(New DataColumn("status_str", GetType(String)))
'add example row - not publised
Dim newDr0 As DataRow = dt.NewRow
newDr0(0) = 0
dt.Rows.Add(newDr0)
'add example row - publised
Dim newDr1 As DataRow = dt.NewRow
newDr1(0) = 1
dt.Rows.Add(newDr1)
For Each dr As DataRow In dt.Rows
Select Case dr(0)
Case 1
dr(1) = "Published"
Case Else
dr(1) = "Not published"
End Select
Next
For Each dr In dt.Rows
Console.WriteLine(dr(0).ToString + " " + dr(1).ToString)
Next
这篇关于在vb.net中更改datatable中列的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文