关于VB.NET中DATAGRID的用法~~~~谢谢~~~急!!!
我在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个字段,是部门编码,部门名称