How to display data from a database in asp.net

Source: Internet
Author: User
asp.net| Data | database | Show the first step: Drag a DataGrid from the left toolbar to the page with ID DataGrid1.

The second step: double-click the blank space, enter the Code writing window. Find

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

Then add the following code:

Dim Strmycon as String = "Server=mis04;user Id=sa;password=little;database=humanresource"

Dim strmycom as String = "SELECT top * 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 ()

Step three, run F5


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.