VB.NET如何将数据表值从整数转换为字符串消息 [英] VB.NET How to Convert Datatables Value from Integer to String Message
本文介绍了VB.NET如何将数据表值从整数转换为字符串消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在用户表列帐户中存储了1,2,3的值。
I've store the values of 1,2,3 in the User table column Account.
然后
Dim DATA As DataTable = executesqlcommand(SELECT ID,Name,Account FROM User)
DataGridView.DataSource = DATA
我希望我的DataGridView.Columns(2)显示为Operator,Supervisor,Manager而不是1,2,3(其中1 =运营商,2 =主管,3 =经理)
And i want my DataGridView.Columns(2) shown as Operator,Supervisor,Manager instead of 1,2,3 (where 1=Operator, 2=Supervisor, 3=Manager)
谢谢,
推荐答案
很抱歉我的回复很晚。
您可以在CellFormatting事件中执行此操作。
You can do this in CellFormatting event.
代码供您参考。
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim dt As DataTable = New DataTable
dt.Columns.Add("ID", System.Type.GetType("System.Int32"))
dt.Columns.Add("Name", System.Type.GetType("System.String"))
dt.Columns.Add("Account", System.Type.GetType("System.String"))
Dim row As DataRow
For i = 0 To 2
row = dt.NewRow()
row("ID") = i
row("Name") = "Name" & i
row("Account") = i + 1
dt.Rows.Add(row)
Next
DataGridView1.DataSource = dt
End Sub
Private Sub DataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
Dim i As Integer
For i = 0 To DataGridView1.RowCount - 1
If DataGridView1.Item(2, i).Value = "1" Then
DataGridView1.Item(2, i).Value = "Operator"
ElseIf DataGridView1.Item(2, i).Value = "2" Then
DataGridView1.Item(2, i).Value = "Supervisor"
ElseIf DataGridView1.Item(2, i).Value = "3" Then
DataGridView1.Item(2, i).Value = "Manager"
End If
Next
End Sub
End Class
希望它对您有所帮助。
最诚挚的问候,
Bob
这篇关于VB.NET如何将数据表值从整数转换为字符串消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文