关于VB.NET中DATAGRID的用法~~~~谢谢~~~急!!!

genienet 2002-07-14 01:55:22
我在DATAGRID中创建了2列,怎么从数据库中把数据添加进去呢?
Public Function Creattable()

Dim myDataTable As DataTable = New DataTable("myTable2")
Dim myDataColumn As DataColumn
Dim myDataRow As DataRow
myDataColumn = New DataColumn()
myDataColumn.DataType = System.Type.GetType("System.Int32")
myDataColumn.ColumnName = "部门编码"
myDataColumn.ReadOnly = True
myDataColumn.Unique = True
' Add the Column to the DataColumnCollection.
myDataTable.Columns.Add(myDataColumn)


'' Create second column.
myDataColumn = New DataColumn()
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "部门名称"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "部门名称"
myDataColumn.ReadOnly = False
myDataColumn.Unique = False
' Add the column to the table.
myDataTable.Columns.Add(myDataColumn)

' Make the ID column the primary key column.
Dim PrimaryKeyColumns(0) As DataColumn
PrimaryKeyColumns(0) = myDataTable.Columns("部门编码")
myDataTable.PrimaryKey = PrimaryKeyColumns

'Instantiate the DataSet variable.
Ds = New DataSet()
'Add the new DataTable to the DataSet.
Ds.Tables.Add(myDataTable)
'DG.DataSource = Ds.Tables.Item(0).DefaultView

DG.SetDataBinding(Ds, "myTable2")
怎么添加行呢?用ADD我知道,但是是空的吧?怎么把数据自动加进去?
加入我的表有2个字段,是部门编码,部门名称
...全文
45 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
genienet 2002-07-14
  • 打赏
  • 举报
回复
楼上的谢谢了,能不能把代码写出来啊,将DATAGRID绑定到数据源?我要用代码添加,不想用空件的形式~~~~~谢谢了~~~~~~
ecsi_liufeng 2002-07-14
  • 打赏
  • 举报
回复
将DATAGRID绑定到数据源,在往数据源里添加记录,DATAGRID.REFRESH

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧