我已经导入了我自己的数据库连接文件,但它不喜欢dbConnectDBOStr字符串
有什么想法吗?
Imports Pirelli.dbPirelli
Partial Class _Default
Inherits System.Web.UI.Page
Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs) Handles MyBase.Load
Dim strCmd As String
Dim dbCmd As SqlCommand
Dim oConn As SqlConnection
Dim dbReader As SqlDataReader
oConn = New SqlConnection(dbConnectDBOStr)连接文件:
Imports System.Data.SqlClient
Namespace Pirelli
Public Class dbPirelli
'Database Server - ENABLE ONE ONLY
Public Const strServerName As String = "[Server]" 'DEV
Public Const dbConnectDBOStr As String = "uid=[USER];password=[PASS];database=[DB];server=" & strServerName & ";Connection Timeout=60;"
End Class
End Namespace我得到了这个错误:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'dbConnectDBOStr' is not declared.
Source Error:
Line 21:
Line 22:
Line 23: oConn = New SqlConnection(dbConnectDBOStr)
Line 24:
Line 25: oConn.Open() 发布于 2014-03-13 02:09:16
由于您不是在处理dbPirelli类的实例,因此您应该使您的类成为静态类,并使用以下命令按名称空间调用它:
Namespace Pirelli
' In VB a static class is called a "Module"
Public Module dbPirelli
'Database Server - ENABLE ONE ONLY
Public Const strServerName As String = "[Server]" 'DEV
Public Const dbConnectDBOStr As String = "uid=[USER];password=[PASS];database=[DB];server=" & strServerName & ";Connection Timeout=60;"
End Module
End Namespace……
' Since you're importing the namespace Pirelli.dbPirelli, you don't need
' to call the namespace as I had previously indicated
oConn = New SqlConnection(dbConnectDBOStr)发布于 2014-03-13 02:09:23
您可以像这样使用它:
oConn = New SqlConnection(dbPirelli.dbConnectDBOStr)https://stackoverflow.com/questions/22360142
复制相似问题