将dataset中的数据填充到dategrid 的中,
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
filldgbm()
End Sub
Public dsbmmc As New Data.DataSet
Public dabmmc As New SqlClient.SqlDataAdapter
Sub filldgbm()
' Dim drdwmc As SqlClient.SqlDataReader
sqlcmd = New SqlClient.SqlCommand
sqlcmd.Connection = objSqlConnection
sqlcmd.CommandText = "select BMID ,BMMC as 部门名称,BMDM as 部门代码 from BM"
dabmmc.SelectCommand = sqlcmd
Try
dabmmc.Fill(dsbmmc, "bm")
dgbmxx.DataSource = dsbmmc.Tables("bm")
' dgbmxx.
dgbmxx.DataMember = "BMID"
dgbmxx.DataMember = "部门名称"
dgbmxx.DataMember = "部门代码"
' dgbmxx.SetDataBinding(dsbmmc, "")
'dgbmxx.SetDataBinding(objDataSet, "bm")
Catch ex As Exception
Finally
End Try
End Sub
Private Sub dgbmxx_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgbmxx.CurrentCellChanged
在此将datagrid 中当前行数据提出赋值给textbox等
tbbmmc.Text = dgbmxx.Item(dgbmxx.CurrentCell.RowNumber, 1)
tbbmdm.Text = dgbmxx.Item(dgbmxx.CurrentCell.RowNumber, 2)
End Sub
本文作者:http://yinzq.itpub.net/ 来源:西桥人家
CIO之家 www.ciozj.com 微信公众号:imciow