2006-11-30
Anthem.NET 安裝
1.下載 http://www.cnblogs.com/Files/aspxcn/WebResourceCompression.zip
然後在web.config加入這一句:
2.下載 http://downloads.sourceforge.net/anthem-dot-net/anthem-1.3.2.zip?modtime=1156191109&big_mirror=0
在web.config\ \ \ 中定义:
然後在web.config加入這一句:
2.下載 http://downloads.sourceforge.net/anthem-dot-net/anthem-1.3.2.zip?modtime=1156191109&big_mirror=0
在web.config
2006-11-29
Asp.Net2.0 使用webcofig整個網站的Trace紀錄
1.在區段加上
2.區段加上
type="System.Diagnostics.TextWriterTraceListener"
initializeData="CustomTrace.txt"
>
2.
initializeData="CustomTrace.txt"
>
Asp.Net2.0 Trace資料的紀錄方式
'1.使用Trace物件寫訊息
Trace.Warn("ADO.NET", "Query Data Start")
'Connection
Trace.Warn("ADO.NET", "Query Data End")
'2.建立一個事件程序(使用TraceContextEventArgs)
Private Sub OnTraceFinished(ByVal sender As Object, ByVal e As TraceContextEventArgs)
End Sub
3.on Page_Load
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'3.註冊Trace的TraceFinished事件去執行OnTraceFinished
AddHandler Trace.TraceFinished, AddressOf OnTraceFinished
End Sub
'4.將所想要紀錄的資訊紀錄在log or database or eventlog or mail
Dim sw As New StreamWriter(Server.MapPath("TraceInfo.log"), True, System.Text.Encoding.Default)
Dim record As TraceContextRecord
'5.使用TraceContextEventArgs的TraceRecords取全部的資料
For Each record In e.TraceRecords
If record.Category = "ADO.NET" Then
sw.WriteLine("Trace紀錄:" + record.Message)
End If
Next
sw.Close()
Trace.Warn("ADO.NET", "Query Data Start")
'Connection
Trace.Warn("ADO.NET", "Query Data End")
'2.建立一個事件程序(使用TraceContextEventArgs)
Private Sub OnTraceFinished(ByVal sender As Object, ByVal e As TraceContextEventArgs)
End Sub
3.on Page_Load
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'3.註冊Trace的TraceFinished事件去執行OnTraceFinished
AddHandler Trace.TraceFinished, AddressOf OnTraceFinished
End Sub
'4.將所想要紀錄的資訊紀錄在log or database or eventlog or mail
Dim sw As New StreamWriter(Server.MapPath("TraceInfo.log"), True, System.Text.Encoding.Default)
Dim record As TraceContextRecord
'5.使用TraceContextEventArgs的TraceRecords取全部的資料
For Each record In e.TraceRecords
If record.Category = "ADO.NET" Then
sw.WriteLine("Trace紀錄:" + record.Message)
End If
Next
sw.Close()
2006-11-22
Asp.Net2.0 SqlCache的使用步驟
1.使用aspnet_regsql開啟資料庫cache功能
aspnet_regsql.exe -S -E -d -et -t <表格>
2.寫入web.config
3.設定datasource
或<%@ OutputCache Duration="999999" SqlDependency="Northwind:Employees" VaryByParam="none" %>
EnableCaching="True" SqlCacheDependency="Northwind:Employees" cacheduration="infinite"
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/caching/SQLInvalidation.aspx
aspnet_regsql.exe -S
2.寫入web.config
3.設定datasource
或<%@ OutputCache Duration="999999" SqlDependency="Northwind:Employees" VaryByParam="none" %>
EnableCaching="True" SqlCacheDependency="Northwind:Employees" cacheduration="infinite"
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/caching/SQLInvalidation.aspx
Asp.Net2.0 物件Catch的應用
絕對時間快取
Cache.Insert("key", TextBox1.Text, Nothing, Now.AddSeconds(5), TimeSpan.Zero)
相對時間快取
Cache.Insert("key", TextBox1.Text, Nothing, DateTime.MaxValue, TimeSpan.FromSeconds(5))
相依Xml檔案
Cache.Insert("key", TextBox1.Text, New System.Web.Caching.CacheDependency(Server.MapPath("Books.xml")))
移除後回呼
Cache.Insert("key", TextBox1.Text, Nothing, Now.AddSeconds(5), TimeSpan.Zero, CacheItemPriority.Default, New CacheItemRemovedCallback(AddressOf RemovedCallback))
回呼函式範例
Public Sub RemovedCallback(ByVal k As String, ByVal v As Object, ByVal r As CacheItemRemovedReason)
Dim sw As New StreamWriter("c:\Log.txt")
sw.WriteLine("Cache(''" & k & "'') 被移除了, 原因是 : " & r.ToString)
sw.Close()
End Sub
Cache.Insert("key", TextBox1.Text, Nothing, Now.AddSeconds(5), TimeSpan.Zero)
相對時間快取
Cache.Insert("key", TextBox1.Text, Nothing, DateTime.MaxValue, TimeSpan.FromSeconds(5))
相依Xml檔案
Cache.Insert("key", TextBox1.Text, New System.Web.Caching.CacheDependency(Server.MapPath("Books.xml")))
移除後回呼
Cache.Insert("key", TextBox1.Text, Nothing, Now.AddSeconds(5), TimeSpan.Zero, CacheItemPriority.Default, New CacheItemRemovedCallback(AddressOf RemovedCallback))
回呼函式範例
Public Sub RemovedCallback(ByVal k As String, ByVal v As Object, ByVal r As CacheItemRemovedReason)
Dim sw As New StreamWriter("c:\Log.txt")
sw.WriteLine("Cache(''" & k & "'') 被移除了, 原因是 : " & r.ToString)
sw.Close()
End Sub
2006-11-20
Asp.Net2.0 實作http handler 加入文字在圖片
1.dll code
Imports System.Web
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Public Class BMPHandler
Implements IHttpHandler
Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
Get
Return True
End Get
End Property
Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
Dim s As String = "text drawing here!"
Dim bmpFile As String = context.Request.PhysicalPath
Dim bmp As Image = Bitmap.FromFile(bmpFile)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim f As New Font("Courier New", 10)
Dim b As New SolidBrush(Color.White)
g.DrawString(s, f, b, 0, 0)
Dim ms As MemoryStream = New MemoryStream
bmp.Save(ms, ImageFormat.Bmp)
context.Response.Clear()
context.Response.ContentType = "IMAGE/BMP"
context.Response.BinaryWrite(ms.ToArray())
context.Response.End()
End Sub
End Class
2.註冊到web.config
Imports System.Web
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Public Class BMPHandler
Implements IHttpHandler
Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
Get
Return True
End Get
End Property
Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
Dim s As String = "text drawing here!"
Dim bmpFile As String = context.Request.PhysicalPath
Dim bmp As Image = Bitmap.FromFile(bmpFile)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim f As New Font("Courier New", 10)
Dim b As New SolidBrush(Color.White)
g.DrawString(s, f, b, 0, 0)
Dim ms As MemoryStream = New MemoryStream
bmp.Save(ms, ImageFormat.Bmp)
context.Response.Clear()
context.Response.ContentType = "IMAGE/BMP"
context.Response.BinaryWrite(ms.ToArray())
context.Response.End()
End Sub
End Class
2.註冊到web.config
Asp.Net2.0 HandleModule的應用
1.新增ErrorHandleModule.class在app_code
2.Implements System.Web.IHttpModule 按下enter,自動產生code
3.加入要執行的code
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
Dim app As HttpApplication = CType(sender, HttpApplication)
Dim ex As Exception = app.Server.GetLastError().GetBaseException()
app.Server.ClearError()
app.Response.Redirect("~/Error.aspx")
End Sub
4.Init加入code
AddHandler context.Error, AddressOf Application_Error
5.註冊到web.config的區段
6.dll的註冊方式
2.Implements System.Web.IHttpModule 按下enter,自動產生code
3.加入要執行的code
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
Dim app As HttpApplication = CType(sender, HttpApplication)
Dim ex As Exception = app.Server.GetLastError().GetBaseException()
app.Server.ClearError()
app.Response.Redirect("~/Error.aspx")
End Sub
4.Init加入code
AddHandler context.Error, AddressOf Application_Error
5.註冊到web.config的
6.dll的註冊方式
Asp.Net2.0 Cookie的應用
'判斷cookie是否存在
If IsNothing(HttpContext.Current.Request.Cookies("CookieName"))
'新增 Cookie 至 Response Cookies 集合中。下列範例顯示完成此工作的兩個方法。
Response.Cookies("userName").Value = "mike"
Response.Cookies("userName").Expires = DateTime.Now.AddDays(1)
Dim aCookie As New HttpCookie("lastVisit")
aCookie.Value = DateTime.Now.ToString
aCookie.Expires = DateTime.Now.AddDays(1)
Response.Cookies.Add(aCookie)
'建立具有子機碼的 Cookie,可以使用許多撰寫單一 Cookie 的語法。下列範例顯示撰寫相同 Cookie 的兩種方法,各具有兩個子機碼:
Response.Cookies("userInfo")("userName") = "mike"
Response.Cookies("userInfo")("lastVisit") = DateTime.Now.ToString
Response.Cookies("userInfo").Expires = DateTime.Now.AddDays(1)
Dim aCookie As New HttpCookie("userInfo")
aCookie.Values("userName") = "mike"
aCookie.Values("lastVisit") = DateTime.Now.ToString
aCookie.Expires = DateTime.Now.AddDays(1)
Response.Cookies.Add(aCookie)
'more
http://www.microsoft.com/taiwan/msdn/library/2003/Mar-2003/vbtchASPNETCookies101.htm
If IsNothing(HttpContext.Current.Request.Cookies("CookieName"))
'新增 Cookie 至 Response Cookies 集合中。下列範例顯示完成此工作的兩個方法。
Response.Cookies("userName").Value = "mike"
Response.Cookies("userName").Expires = DateTime.Now.AddDays(1)
Dim aCookie As New HttpCookie("lastVisit")
aCookie.Value = DateTime.Now.ToString
aCookie.Expires = DateTime.Now.AddDays(1)
Response.Cookies.Add(aCookie)
'建立具有子機碼的 Cookie,可以使用許多撰寫單一 Cookie 的語法。下列範例顯示撰寫相同 Cookie 的兩種方法,各具有兩個子機碼:
Response.Cookies("userInfo")("userName") = "mike"
Response.Cookies("userInfo")("lastVisit") = DateTime.Now.ToString
Response.Cookies("userInfo").Expires = DateTime.Now.AddDays(1)
Dim aCookie As New HttpCookie("userInfo")
aCookie.Values("userName") = "mike"
aCookie.Values("lastVisit") = DateTime.Now.ToString
aCookie.Expires = DateTime.Now.AddDays(1)
Response.Cookies.Add(aCookie)
'more
http://www.microsoft.com/taiwan/msdn/library/2003/Mar-2003/vbtchASPNETCookies101.htm
2006-11-15
Asp.Net2.0 動態載入UserControl
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'Dim c As New Calendar
Dim c As Control = Page.LoadControl("DatePicker.ascx")
PlaceHolder1.Controls.Add(c)
End Sub
'Dim c As New Calendar
Dim c As Control = Page.LoadControl("DatePicker.ascx")
PlaceHolder1.Controls.Add(c)
End Sub
Asp.Net2.0 傳送UserControl的控制項的值
Public Property Text() As String
Get
Return TextBox1.Text
End Get
Set(ByVal value As String)
TextBox1.Text = value
End Set
End Property
Get
Return TextBox1.Text
End Get
Set(ByVal value As String)
TextBox1.Text = value
End Set
End Property
2006-11-13
Asp.Net2.0 自訂元件
一個簡單的class
Public Class MyFunction
Shared Function add(ByVal x As Integer, ByVal y As Integer)
Return x + y
End Function
End Class
可新增一個NameSpace
範例寫一個insert
Sub InsertTitle(ByVal title_id As String, ByVal title As String, ByVal type As String, ByVal price As Decimal)
Dim cn As New SqlConnection("Server=localhost;Database=Pubs;UID=sa;PWD=;")
Dim cmd As New SqlCommand("insert into titles (title_id,title,type,price) values (@title_id,@title,@type,@price)", cn)
cmd.Parameters.AddWithValue("@title_id", title_id)
cmd.Parameters.AddWithValue("@title", title)
cmd.Parameters.AddWithValue("@type", type)
cmd.Parameters.AddWithValue("@price", price)
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
End Sub
Public Class MyFunction
Shared Function add(ByVal x As Integer, ByVal y As Integer)
Return x + y
End Function
End Class
可新增一個NameSpace
範例寫一個insert
Sub InsertTitle(ByVal title_id As String, ByVal title As String, ByVal type As String, ByVal price As Decimal)
Dim cn As New SqlConnection("Server=localhost;Database=Pubs;UID=sa;PWD=;")
Dim cmd As New SqlCommand("insert into titles (title_id,title,type,price) values (@title_id,@title,@type,@price)", cn)
cmd.Parameters.AddWithValue("@title_id", title_id)
cmd.Parameters.AddWithValue("@title", title)
cmd.Parameters.AddWithValue("@type", type)
cmd.Parameters.AddWithValue("@price", price)
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
End Sub
2006-11-11
ASP2.0 DataSet 匯出XML文件
Dim connString As String = ConfigurationManager.ConnectionStrings("DBConnectionString").ConnectionString
Dim con As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection(connString)
Dim strsql As String = "select * from dbtable"
Dim adapter As New Data.SqlClient.SqlDataAdapter(strsql, con)
Dim ds As New System.Data.DataSet()
adapter.Fill(ds)
Dim xmlFile As String = "new.xml"
' 建立StreamWriter物件
Dim sw As IO.StreamWriter = New IO.StreamWriter(Server.MapPath(xmlFile))
' 寫入XML文件
ds.WriteXml(sw)
sw.Close()
Dim con As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection(connString)
Dim strsql As String = "select * from dbtable"
Dim adapter As New Data.SqlClient.SqlDataAdapter(strsql, con)
Dim ds As New System.Data.DataSet()
adapter.Fill(ds)
Dim xmlFile As String = "new.xml"
' 建立StreamWriter物件
Dim sw As IO.StreamWriter = New IO.StreamWriter(Server.MapPath(xmlFile))
' 寫入XML文件
ds.WriteXml(sw)
sw.Close()
2006-11-10
Asp.Net2.0 瀏覽器語系
1.判斷使用者語系
web.config或 網頁 @page Culture="auto"
2.
Response.Write(Request.UserLanguages(0)) '取得語系
web.config
2.
Response.Write(Request.UserLanguages(0)) '取得語系
Asp.Net2.0 建立MemberShip在web.config
1.
providerName="System.Data.SqlClient" />
2.
type="System.Web.Security.SqlMembershipProvider" />
3.
2.
3.
Asp.Net2.0 SqlDataSource Selecting Selected用法
一個簡單的查詢資料庫
Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)
If Page.IsPostBack And TextBox1.Text.Length <= 2 Then
e.Cancel = True
Response.Write("關鍵字太短...")
End If
End Sub
Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)
Response.Write("查出" & e.AffectedRows & "筆")
End Sub
Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)
If Page.IsPostBack And TextBox1.Text.Length <= 2 Then
e.Cancel = True
Response.Write("關鍵字太短...")
End If
End Sub
Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)
Response.Write("查出" & e.AffectedRows & "筆")
End Sub
Asp.Net2.0 GridView RowDataBound用法
If e.Row.RowType = DataControlRowType.Header Then '指定需要修改的區段為header
e.Row.BackColor = Drawing.Color.Brown
End If
If e.Row.RowType = DataControlRowType.DataRow Then'指定需要修改的區段為資料
Dim price As Decimal = CType(DataBinder.Eval(e.Row.DataItem, "UnitPrice"), Decimal) '直接取得dataitem
Dim label1 As Label = CType(GridView1.FindControl("label1.text"), Label)
End If
If e.Row.RowType = DataControlRowType.Footer Then '指定需要修改的區段為footer
e.Row.Cells(4).Text = counter
End If
e.Row.BackColor = Drawing.Color.Brown
End If
If e.Row.RowType = DataControlRowType.DataRow Then'指定需要修改的區段為資料
Dim price As Decimal = CType(DataBinder.Eval(e.Row.DataItem, "UnitPrice"), Decimal) '直接取得dataitem
Dim label1 As Label = CType(GridView1.FindControl("label1.text"), Label)
End If
If e.Row.RowType = DataControlRowType.Footer Then '指定需要修改的區段為footer
e.Row.Cells(4).Text = counter
End If
Asp.Net2.0 Dropdownlist 加入item
Protected Sub DropDownList1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
DropDownList1.Items.Insert(0, New ListItem("請選擇", "0"))
End Sub
DropDownList1.Items.Insert(0, New ListItem("請選擇", "0"))
End Sub
Asp.Net2.0 WebCofig Appsettings標籤
1.web.config
2.讀取
Response.Write(ConfigurationManager.AppSettings("RealDocumentPath"))
3.修改(RunTime)
ConfigurationManager.AppSettings.Set("RealDocumentPath", TextBox1.Text)
4.寫入
Dim c As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration("/所在目錄")
c.AppSettings.Settings("RealDocumentPath").Value = TextBox1.Text
c.Save()
PS:需給該目錄有寫入的權限
2.讀取
Response.Write(ConfigurationManager.AppSettings("RealDocumentPath"))
3.修改(RunTime)
ConfigurationManager.AppSettings.Set("RealDocumentPath", TextBox1.Text)
4.寫入
Dim c As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration("/所在目錄")
c.AppSettings.Settings("RealDocumentPath").Value = TextBox1.Text
c.Save()
PS:需給該目錄有寫入的權限
Asp.Net2.0 取得web.config 標籤內容
<%@ Import Namespace="System.Web.Configuration" %>
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim c As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration("/所在目錄")
Dim pages As PagesSection = CType(c.GetSection("system.web/pages"), PagesSection)
Response.Write(pages.ElementInformation.Type.ToString())
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim c As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration("/所在目錄")
Dim pages As PagesSection = CType(c.GetSection("system.web/pages"), PagesSection)
Response.Write(pages.ElementInformation.Type.ToString())
End Sub
Asp.Net2.0 自訂義WebCofig標籤
1.加入到web.config
2.呼叫
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim settings As Hashtable = CType(ConfigurationManager.GetSection("customerService"), Hashtable)
Response.Write(settings("email"))
End Sub
2.呼叫
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim settings As Hashtable = CType(ConfigurationManager.GetSection("customerService"), Hashtable)
Response.Write(settings("email"))
End Sub
2006-11-08
Asp.Net2.0 StoredProcedure and Parameter
Dim cn As New SqlConnection("Server=localhost;Database=Northwind;UID=sa;PWD=P@ssw0rd;")
Dim cmd As New SqlCommand("SalesByCategory", cn)
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@CategoryName", TextBox1.Text)
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
dr.Read()
Response.Write(dr(0))
dr.Close()
cn.Close()
Dim cmd As New SqlCommand("SalesByCategory", cn)
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@CategoryName", TextBox1.Text)
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
dr.Read()
Response.Write(dr(0))
dr.Close()
cn.Close()
Asp.Net2.0 ExecuteScalar
Dim cn As New SqlConnection("Server=localhost;Database=Northwind;UID=sa;PWD=P@ssw0rd;")
Dim cmd As New SqlCommand("select count(orderid) from orders", cn)
cn.Open()
Dim count As Integer = cmd.ExecuteScalar
cn.Close()
Response.Write(count)
Dim cmd As New SqlCommand("select count(orderid) from orders", cn)
cn.Open()
Dim count As Integer = cmd.ExecuteScalar
cn.Close()
Response.Write(count)
Asp.Net2.0 DataReader
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim cn As New SqlConnection("Server=localhost;Database=Northwind;UID=sa;PWD=P@ssw0rd;")
Dim cmd As New SqlCommand("select * from employees", cn)
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
Do While dr.Read
Response.Write(dr("LastName") & "
")
Loop
dr.Close()
cn.Close()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim cn As New SqlConnection("Server=localhost;Database=Northwind;UID=sa;PWD=P@ssw0rd;")
Dim cmd As New SqlCommand("select * from employees;select * from products", cn)
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
Do
Do While dr.Read
Response.Write(dr(0) & " -- " & dr(1) & "
")
Loop
Response.Write("
")
Loop While dr.NextResult
dr.Close()
cn.Close()
End Sub
Dim cn As New SqlConnection("Server=localhost;Database=Northwind;UID=sa;PWD=P@ssw0rd;")
Dim cmd As New SqlCommand("select * from employees", cn)
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
Do While dr.Read
Response.Write(dr("LastName") & "
")
Loop
dr.Close()
cn.Close()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim cn As New SqlConnection("Server=localhost;Database=Northwind;UID=sa;PWD=P@ssw0rd;")
Dim cmd As New SqlCommand("select * from employees;select * from products", cn)
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
Do
Do While dr.Read
Response.Write(dr(0) & " -- " & dr(1) & "
")
Loop
Response.Write("
")
Loop While dr.NextResult
dr.Close()
cn.Close()
End Sub
Asp.Net2.0 DataView
Dim cn As New SqlConnection("Server=localhost;Database=Northwind;UID=sa;PWD=P@ssw0rd;")
Dim da As New SqlDataAdapter("select ProductID, ProductName, UnitPrice from Products", cn)
Dim ds As New DataSet
da.Fill(ds, "Products")
'1,
'Dim dv As New DataView(ds.Tables("Products"))
'2,
Dim dv As DataView = ds.Tables("Products").DefaultView
dv.RowFilter = "UnitPrice>50"
dv.Sort = "UnitPrice"
GridView1.DataSource = dv
GridView1.DataBind()
dv.RowFilter = "UnitPrice<20"
dv.Sort = "UnitPrice desc"
GridView2.DataSource = dv
GridView2.DataBind()
dv.RowFilter = "UnitPrice>=20 and UnitPrice<=50"
GridView3.DataSource = dv
GridView3.DataBind()
Dim da As New SqlDataAdapter("select ProductID, ProductName, UnitPrice from Products", cn)
Dim ds As New DataSet
da.Fill(ds, "Products")
'1,
'Dim dv As New DataView(ds.Tables("Products"))
'2,
Dim dv As DataView = ds.Tables("Products").DefaultView
dv.RowFilter = "UnitPrice>50"
dv.Sort = "UnitPrice"
GridView1.DataSource = dv
GridView1.DataBind()
dv.RowFilter = "UnitPrice<20"
dv.Sort = "UnitPrice desc"
GridView2.DataSource = dv
GridView2.DataBind()
dv.RowFilter = "UnitPrice>=20 and UnitPrice<=50"
GridView3.DataSource = dv
GridView3.DataBind()
Asp.Net2.0 DataSet
Dim cn As New SqlConnection("Server=localhost;Database=Northwind;UID=sa;PWD=;")
Dim da As New SqlDataAdapter("select EmployeeID,LastName,FirstName,Title from employees", cn)
Dim ds As New DataSet
da.Fill(ds, "employees")
GridView1.DataSource = ds.Tables("employees")
GridView1.DataBind()
Dim da As New SqlDataAdapter("select EmployeeID,LastName,FirstName,Title from employees", cn)
Dim ds As New DataSet
da.Fill(ds, "employees")
GridView1.DataSource = ds.Tables("employees")
GridView1.DataBind()