"
未将对象引用设置到对象的实例"
在一个类中取web.config内的值的时候,提示 "未将对象引用设置到对象的实例 ",请问如何解决,谢谢.
web.config 中代码如下:
-------------------------------------
configuration xmlns= "http://schemas.microsoft.com/.NetConfiguration/v2.0 ">
<appSettings>
<!--注释:数据库连接字串-->
<add key= "Datebase " value= "contract.mdb " />
</appSettings>
--------------------------------------
在类中引用该值,代码如下:
------------------------------------
Imports Microsoft.VisualBasic
Imports System
Imports System.Web
Imports System.Configuration
Imports System.Data
Imports System.Data.OleDB
Namespace WJCclass
Public Class FindRecord
Public Function getMaxId() As Integer
Dim mDatabase As String
mDatabase = System.Configuration.ConfigurationManager.AppSettings( "Database ").ToString()
'Dim mDatabase As String = "contract.mdb "
Dim conDB As OleDbConnection
Dim selectDB As OleDbCommand
Dim MaxId As Integer
Dim mDBName As String = System.Web.HttpContext.Current.Server.MapPath(mDatabase)
conDB = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA Source= " + mDBName)
conDB.Open()
selectDB = New OleDbCommand( "select iif(max(BranchID) is null,0,max(BranchID)) from branch ", conDB)
MaxId = selectDB.ExecuteScalar()
If MaxId = 0 Then
MaxId = 1
Else
MaxId = MaxId + 1