明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

如何在ASP.NET中顯示數(shù)據(jù)庫中的數(shù)據(jù)

[摘要]第一步:從左邊工具欄中拖一個datagrid到頁面上,ID為datagrid1 .第二步:雙擊空白處,進入代碼編寫窗口.找到Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handl...
第一步:從左邊工具欄中拖一個datagrid到頁面上,ID為datagrid1 .

第二步:雙擊空白處,進入代碼編寫窗口.找到

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

在其后加入如下代碼:

Dim strmycon As String = "server=mis04;user id=sa;password=little;database=humanresource"

Dim strmycom As String = "select top 10 * from tbl_user"

Dim mycon As New SqlClient.SqlConnection(strmycon)

Dim mycom As New SqlClient.SqlCommand(strmycom, mycon)

mycon.Open()

Dim myreader As SqlClient.SqlDataReader

myreader = mycom.ExecuteReader()

DataGrid1.DataSource = myreader

DataGrid1.DataBind()

mycon.Close()

第三步