有人能帮助我在DataGridView vb.net中显示数据吗?

有人能帮助我在DataGridView vb.net中显示数据吗?,vb.net,datagridview,dataadapter,Vb.net,Datagridview,Dataadapter,当我以不同的方式编写这个应用程序时,我没有太多的运气,所以我使用DataAdapter而不是TableAdapter方法重新编写了程序 我需要帮助获取数据显示在vb.net的DataGridView工具中我不确定我在这里做错了什么。。。数据在列表框中显示得很好。但不会显示在DataGridView工具中。DataGridView将显示字符串的长度。不确定为什么。。。请参阅下面的代码。(顺便说一句,我创建列表框只是为了测试,不想使用它) 程序的作用:用户在每个房屋项目(例如:水泥工程)上打勾,项目

当我以不同的方式编写这个应用程序时,我没有太多的运气,所以我使用DataAdapter而不是TableAdapter方法重新编写了程序

我需要帮助获取数据显示在vb.net的DataGridView工具中我不确定我在这里做错了什么。。。数据在列表框中显示得很好。但不会显示在DataGridView工具中。DataGridView将显示字符串的长度。不确定为什么。。。请参阅下面的代码。(顺便说一句,我创建列表框只是为了测试,不想使用它)

程序的作用:用户在每个房屋项目(例如:水泥工程)上打勾,项目将获得所选项目所需的工具列表。项目名称位于复选框中,checkChanged事件将文本分配到SQL select语句中的变量“ProjectName”

Private Sub Button1_Click_2(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim connection As OleDbConnection

    Dim cmdString As String = "Select Distinct ToolName,Notes From Tools Where ProjectName = '" & carpentry & "' or ProjectName = '" & cementWork & "' Or ProjectName= '" & dryWall & "' Or ProjectName = '" & electrical _
                & "' Or ProjectName = '" & HVAC & "' Or ProjectName = '" & laminateFlooring & "' Or ProjectName = '" & painting & "' Or ProjectName = '" & plumbing _
                & "' Or ProjectName = '" & texture & "' Or ProjectName = '" & tileWork & "' Or ProjectName = '" & vinylFlooring & "'"

    connection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=SaintEnterprises.mdb")


    Dim adapter As New OleDbDataAdapter(cmdString, connection)

    Dim tools As New DataSet

    connection.Open()

    adapter.Fill(tools)

    Dim toolslist As New List(Of String)


    ListBox1.Items.Clear()

    For Each row As DataRow In tools.Tables(0).Rows

        Dim s As String = row("toolname").ToString

        'toolslist.Add(row("toolName").ToString) 'Does same thing as line toollist.add(s) below


        toolslist.Add(s.ToString) 'add to List

        ListBox1.Items.Add(s.ToString) 'Displays the type of tools based on the query. 


    Next

    ToolsDataGridView.DataSource = toolslist 'displays the length (Total # of letters) of each toolname'

End Sub

虽然我可能不会再使用TableAdapter进行编程,但如果您想了解我使用TableAdapter编程此应用程序的方法,请参阅此链接。

我认为您需要一个DataTable来填充DataGridView。将数据集行转换为数据表

我已经试过了,这对我来说很好(假设您的数据库连接正常)

Dim oData As New System.Data.DataTable

For Each oRow As System.Data.DataRow In tools.Tables(0).Rows
    oData.ImportRow(oRow)
Next

ToolsDataGridView.DataSource = oData