明辉手游网中心:是一个免费提供流行视频软件教程、在线学习分享的学习平台!

如何在ASP.NET中显示数据库中的数据

[摘要]第一步:从左边工具栏中拖一个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()

第三步