2012-04-29 84 views
0

我在windows窗体上有一个DataGridView,只是从工具中拖动和放弃。 现在我想使用DataSet或DataTable将数据设置为此GridView。如何通过编码来设置它。 我使用SQL Server 2008和Visual Studio 2010在VB.net中将数据设置为DataGridView

请帮我....

+0

再检查一下该实施例中http://vbdotnetheaven.com/UploadFile/mahesh/DataGridSamp04232005050133AM/DataGridSamp.aspx – 2012-04-29 03:36:39

回答

0

这里有一个简单的例子:

昏暗的DS作为新的数据集()
昏暗DA作为新的SqlDataAdapter ()
昏暗SelectQ为字符串=查询
昏暗CN作为新的SqlConnection(的ConnectionString)
DA.SelectCommand =新SqlClient.SqlCommand(SelectQ) DACusto mers.SelectCommand.Connection = CN
CN.Open
DA.fill(DS, “diseredTable”)
CN.Close
昏暗BS作为新的BindingSource
BS.DataSource = DS
BS.DataMember =” desiredTable”
DataGridView1.DataSource = BS

相关问题