一、程序功能:將orders表和Customers表中的字段綁定到文本框
二、窗體設計
1、新建ASP.Net Web應用程序,命名為Sql4,選擇保存路徑然後點擊確定。
2、向窗體中添加兩個Label和兩個Textbox控件,窗體界面見下圖
三、代碼設計
切換到代碼窗口,添加代碼如下:
Imports System.Data.SqlClIEnt
Public Class WebForm1
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim scon As New SqlConnection("server=localhost;database=northwind;integrated security=true")
Dim i As Integer = 10248
'創建一個數據適配器,查詢訂單表中的訂單號和客戶表的公司名稱,此處使用了表格別名
Dim sda As New SqlDataAdapter _
("select o.orderid, c.companyname from orders o, customers c where o.customerid=c.customerid and o.orderid=" & i.ToString, scon)
Dim ds As New DataSet
Try
sda.Fill(ds)
Catch ex As Exception
End Try
'綁定數據
TextBox1.Text = ds.Tables(0).Rows(0).Item(0)
TextBox2.Text = ds.Tables(0).Rows(0).Item(1)
End Sub
End Class