Application_Start里
Dim connstr As String = "server=127.0.0.1;database=ceshi;User Id=sa;pwd=7788; "
Ds1 = New DataSet9
Dim adp As System.Data.SqlClient.SqlDataAdapter
adp = New System.Data.SqlClient.SqlDataAdapter( "SELECT * FROM config ", connstr)
adp.Fill(Ds1, "config ")
Me.Application.Add( "ds ", Ds1)
页面里.
Dim ds As DataSet = Me.Application( "ds ")
Dim dvs As New DataView(ds.) 就是这里.我用ds.table(0)就可以.用ds.config就找不到...为什么啊
Me.Response.Write(dvs(0)( "block "))
还有.Application怎么不能定义
Imports System.Data
Imports System.Data.SqlClient
------解决方案--------------------------------------------------------
我还想把他写成一个类..只要给段SQL语句.就可以填充了。不知道该怎么弄?
dataset9是自己手动建的!!
————————————————————————————————————————
在app_code中增加一个.cs文件,写:
public class GlobalConfig
Private _ds As DataSet9
Public Shared ReadOnly Property ds() As DataSet9
Get
If _ds Is Nothing Then
Dim connstr As String = "server=127.0.0.1;database=ceshi;User Id=sa;pwd=7788; "
_ds = New DataSet9
Dim adp As System.Data.SqlClient.SqlDataAdapter
adp = New System.Data.SqlClient.SqlDataAdapter( "SELECT * FROM config ", connstr)
adp.Fill(_ds, "config ")
End If
Return _ds
End Get
End Property
end class
然后,在网站项目中任何地方都可以写 GlobalConfig.ds 来读取。
注意,asp.net中(包括asp.net1.1中)完全不需要Application(...),这个只是为了给asp程序员过渡思想用的。在asp.net中,应该使用静态变量来管理那些在老式asp中写在Application(...)中的东西。