简体   繁体   English

在VB.net中将数据设置为DataGridView

[英]Setting data to DataGridView in VB.net

I have a DataGridView on windows Form, just draged and droped from tools. 我在Windows Form上有一个DataGridView,只需将其拖放到工具中即可。 Now I want to set data to this gridview using DataSet or DataTable. 现在,我想使用DataSet或DataTable将数据设置到此gridview。 How can set it by coding. 如何通过编码设置。 I am using SQL Server 2008 and VS 2010 我正在使用SQL Server 2008和VS 2010

Please Help me.... 请帮我....

here's a quick example: 这是一个简单的例子:

Dim DS As New DataSet() 昏暗的DS作为新的DataSet()
Dim DA As New SqlDataAdapter() 昏暗的DA作为新的SqlDataAdapter()
Dim SelectQ as String = Query 昏暗的SelectQ作为字符串=查询
Dim CN As New SqlConnection(ConnectionString) Dim CN作为新的SqlConnection(ConnectionString)
DA.SelectCommand = New SqlClient.SqlCommand(SelectQ) DACustomers.SelectCommand.Connection = CN DA.SelectCommand =新建SqlClient.SqlCommand(SelectQ)DACustomers.SelectCommand.Connection = CN
CN.Open 中国公开赛
DA.fill(DS, "diseredTable") DA.fill(DS,“ diseredTable”)
CN.Close 关闭
Dim BS As New BindingSource 昏暗的BS作为新的BindingSource
BS.DataSource = DS BS.DataSource = DS
BS.DataMember = ”desiredTable” BS.DataMember =“所需表”
DataGridView1.DataSource = BS DataGridView1.DataSource = BS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM