<Script Language="VB" RunAt="Server"> Function createdatasource() Dim conn AS SQLConnection Dim connstr As String Dim strsql AS String Dim sqlCmd AS SQLDataSetCommand Dim ds AS New DataSet '连接数据库 connstr= "Server=NHGA-D36KQ26TWB;DataBase=NorthWind;Pwd=;Uid=sa" conn= New SQLConnection(connstr) 'SQL语句 strsql="Select * from Products " '建立DataSet sqlCmd=New SQLDataSetCommand(strsql,conn) '将表Products加入DataSet sqlCmd.FillDataset(ds,"Products")
return ds.Tables("Products").DefaultView end Function
'绑定数据函数 sub BindGrid() DataGrid1.DataSource=CreateDataSource() DataGrid1.DataBind() End Sub
'页面登录 Sub Page_Load(Source AS Object,E AS EventArgs) CreatedataSource() BindGrid() End Sub </Script>