【问题标题】:Getting the data from the program to GridView in VB.NET在 VB.NET 中从程序中获取数据到 GridView
【发布时间】:2018-03-01 21:43:07
【问题描述】:

我正在尝试将程序中的数据(即 Id、FirstName 和 LastName)发布到网格视图中。我根本没有网格。我把网格装箱了。感谢您的帮助。

我尝试过的:

 If results.Rows.Count > 1 Then
 Dim ds As DataSet = GetDataItem(_Id, _FirstName, _LastName)

 If (ds.Tables.Count > 0) Then
 GridView1.DataSource = ds
 GridView1.DataBind()
 End If
 End If

它不起作用。我跑的时候看不到桌子。任何人都可以帮忙吗?谢谢。

【问题讨论】:

  • 我建议您使用调试器单步执行您的代码。
  • 怎么不工作?错误信息?是否到达GridView1.DataSource = ds

标签: asp.net vb.net gridview webforms


【解决方案1】:

请浏览:“VB.NET中的GridView控件”

Private sqlDataAdapter As SqlDataAdapter
Private sqlConnection As SqlConnection
Private dataSet As New DataSet()
Private sqlCommand As New SqlCommand()

Public Sub BindData()
    sqlConnection = New SqlConnection("YourConnectionString")
    sqlCommand.CommandText = "Select _Id, _FirstName, _LastName from YourTableName"
    sqlCommand.Connection = sqlConnection
    sqlDataAdapter = New SqlDataAdapter(sqlCommand)
    sqlDataAdapter.Fill(dataSet)
    sqlConnection.Open()
    sqlCommand.ExecuteNonQuery()
    GridView1.DataSource = dataSet
    GridView1.DataBind()
    sqlConnection.Close()
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-14
    • 1970-01-01
    相关资源
    最近更新 更多