我是NET的新手我已经在3天内无法解决这个问题了![1
数据库名称为Tbl_Employees,Tbl_Project 我必须使用project_id作为它们之间的主键从上面两个表中获取Username和Project两个字段,并在网格视图中加载数据。加载网格所需的输入
答案 0 :(得分: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