ASP.NET: Thực thi truy vấn SELECT sử dụng đối tượng SQLCommand

Người đăng: share-nhungdieuhay on Thứ Bảy, 27 tháng 4, 2013


<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>

<script language="VB" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)

Dim conn As New SQLConnection("server=LOCALHOST;User id='sa';password='123';database=Northwind")
Dim cmd As New SqlCommand("Select categoryName from Categories", conn)
cmd.Connection.Open()

Dim reader As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While reader.Read()
response.Write(reader.GetString(1) & "<br/>")
End While
reader.Close()
conn.Close()
end sub
</script>

{ 0 nhận xét... read them below or add one }

Đăng nhận xét