1

我是 NET 的新手,我从 3 天以来一直在与这个问题作斗争,无法解决![ 1

数据库名称是 Tbl_Employees,Tbl_Project 我必须使用 project_id 作为它们之间的主键从上述两个表中获取用户名和项目两个字段,并将数据加载到网格视图中。加载网格所需的输入

在此处输入图像描述

4

1 回答 1

0

我不确定您到底需要什么,但它似乎是网格视图的基础知识。请使用这个出色的参考来帮助您解决问题。http://technico.qnownow.com/tag/gridview/

因为标签已从 c# 更改为 vb.net,所以我将保留我之前的答案。请尝试以下方法。我添加了一个SqlCommand

VB.NET代码 _

Dim da As New SqlDataAdapter
    Dim DS As New DataSet
    Dim mySelectQuery As String = "SELECT dbo.Tbl_Project.Project, dbo.Tbl_Employees.User_Name FROM dbo.Tbl_Employees INNER JOIN dbo.Tbl_Project ON dbo.Tbl_Employees.Project_ID = dbo.Tbl_Project.Project_ID"
    Dim ConnString As String = "Data Source=yourSQLServer; Initial Catalog=yourDB; User Id=yourUserName; Password=yourPwd;" ''Change to you database/server specifics
    Dim myConnection As New SqlConnection(ConnString)
    Dim myCommand As New SqlCommand(mySelectQuery, myConnection)
    myConnection.Open()
    da.SelectCommand = myCommand
    da.Fill(DS,"Project")
    If Not DS.Tables(0).Rows.Count > 0 Then
        MessageBox.Show("There were no results found. ", "No Results Found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    Else
        gridview3.DataSource = Ds
    gridview3.DataBind()

        myConnection.Close()
    End If

对连接字符串的引用 http://www.sql-server-helper.com/sql-server-2008/sqlconnection-connection-string.aspx

于 2012-09-14T10:11:50.557 回答