2010-01-09 52 views

回答

0

1. 把你的MS Access數據庫放到你的vb.net的「App_Data」文件中。現在, 假設您的MS Access數據庫表名是'customer' ,並且您有ID,名稱和地址。

文本框:

2.在您的pageName.aspx例如 txtid

按鈕:查找

的AccessDataSource:AccessDataSource1

GridView控件:GridView1

一) AccessDataSource1按箭頭>然後按「配置數據源...」。按Browse(瀏覽),從「App_Data」文件中選擇你的MS Access數據庫並點擊Next。選擇「指定自定義SQL語句或存儲過程」,然後單擊下一步。把它放在SQL語句框SELECT ID, Name, address FROM customer WHERE (ID = ?)中,然後點擊下一步。在'Parameter Source'中選擇'Control',在'ControlID'中選擇txtid並點擊Next。按完成。

b)在GridView1中按箭頭>然後在'選擇數據源'中選擇'AccessDataSource1'。

b)就發現雙擊把VB代​​碼:

Imports System.Data 
Partial Class pageName 
    Inherits System.Web.UI.Page 

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 
     AccessDataSource1.DataSourceMode = SqlDataSourceMode.DataReader 
     Dim reader As IDataReader = CType(AccessDataSource1.Select(DataSourceSelectArguments.Empty), IDataReader) 
     Dim flag As Integer 
     flag = 0 
     If reader.Read Then 
      txtid.Text = reader("id") 
      txtname.Text = reader("name") 
      txtaddress.Text = reader("address") 
          flag = 1 
     End If 
     If flag = 0 Then 
      MsgBox("invalid customer id ... !") 
     End If 
    End Sub 

     End Class 
相關問題