如何在数据表中动态创建列并为其赋值? [英] How to dynamically create columns in datatable and assign values to it?

查看:24
本文介绍了如何在数据表中动态创建列并为其赋值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在运行时在数据表中创建列并为其分配值.我怎样才能在 vb.net 中做到这一点.任何样品请...

I will have to create columns in datatable during runtime and assign values to it. How can i do it in vb.net. Any sample please...

推荐答案

如果你想在 VB.Net 中创建动态/运行时数据表,那么你应该按照下面提到的这些步骤:

If you want to create dynamically/runtime data table in VB.Net then you should follow these steps as mentioned below :

  • 创建数据表对象.
  • 将列添加到该数据表对象中.
  • 将带有值的行添加到对象中.

例如.

Dim dt As New DataTable

dt.Columns.Add("Id", GetType(Integer))
dt.Columns.Add("FirstName", GetType(String))
dt.Columns.Add("LastName", GetType(String))

dt.Rows.Add(1, "Test", "data")
dt.Rows.Add(15, "Robert", "Wich")
dt.Rows.Add(18, "Merry", "Cylon")
dt.Rows.Add(30, "Tim", "Burst")

这篇关于如何在数据表中动态创建列并为其赋值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆