在本地安装好.Net FrameworkSD。
test.vb Namespace myNamespaceImports System
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Public Class myClass1
Public Shared Function DatabaseConnection As SqlConnection
DatabaseConnection = New SqlConnection(ConfigurationSettings.AppSettings("SQLConnectionString"))
End Function
End Class
End Namespace
这是一个连接数据库的Class,这样每次调用只要写:
Dim myConnection As SqlConnection
myConnection = myClass1.DatabaseConnection
数据库的登陆信息都写在网站根目录下的 web.config,然后用就写ConfigurationSettings.AppSettings("SQLConnectionString")),因为ConfigurationSettings属于System.Configuration所以要写Import。附上web.config:
| <configuration> <system.web> <customErrors mode="Off" /> <compilation debug="true" /> </system.web> <appSettings> <add key="SQLConnectionString" value="server=servername;uid=username;pwd=password;database=databasename" /> </appSettings> </configuration> |
打开DOS,写入 vbc /r:system.data.dll /r:system.dll /t:library /out:z:/bin/
test.dll z:/bin/test.vb 把编译后的test.dll放到bin目录下。(/r:是调用其他的dll, /t:是说明要生成dll, /out:是放置的目录, 最后是源文件)
| Imports System Imports System.IO Imports System.Data Imports System.Data.SqlClient Imports System.Configuration Namespace myNamespace |
这是一个连接数据库的Class,这样每次调用只要写:
Dim myConnection As SqlConnection
myConnection = myClass1.DatabaseConnection
数据库的登陆信息都写在网站根目录下的 web.config,然后用就写ConfigurationSettings.AppSettings("SQLConnectionString")),因为ConfigurationSettings属于System.Configuration所以要写Import。附上web.config:
| <configuration> <system.web> <customErrors mode="Off" /> <compilation debug="true" /> </system.web> <appSettings> <add key="SQLConnectionString" value="server=servername;uid=username;pwd=password;database=databasename" /> </appSettings> </configuration> |
打开DOS,写入 vbc /r:system.data.dll /r:system.dll /t:library /out:z:/bin/
test.dll z:/bin/test.vb 把编译后的test.dll放到bin目录下。(/r:是调用其他的dll, /t:是说明要生成dll, /out:是放置的目录, 最后是源文件)
| Imports System Imports System.IO Imports System.Data Imports System.Data.SqlClient Imports System.Configuration Namespace myNamespace |
这是一个连接数据库的Class,这样每次调用只要写:
Dim myConnection As SqlConnection
myConnection = myClass1.DatabaseConnection
数据库的登陆信息都写在网站根目录下的 web.config,然后用就写ConfigurationSettings.AppSettings("SQLConnectionString")),因为ConfigurationSettings属于System.Configuration所以要写Import。附上web.config:
| <configuration> <system.web> <customErrors mode="Off" /> <compilation debug="true" /> </system.web> <appSettings> <add key="SQLConnectionString" value="server=servername;uid=username;pwd=password;database=databasename" /> </appSettings> </configuration> |
打开DOS,写入 vbc /r:system.data.dll /r:system.dll /t:library /out:z:/bin/
test.dll z:/bin/test.vb 把编译后的test.dll放到bin目录下。(/r:是调用其他的dll, /t:是说明要生成dll, /out:是放置的目录, 最后是源文件)
testdll.aspx 完整调用
<%@ Import Namespace="myNamespace" %> <script language="vb" runat="server"> <html> <body> |
博客介绍了在本地安装好.Net Framework SD后,使用Class连接数据库的方法,数据库登陆信息写在web.config中,需使用Import引入相关内容。还说明了在DOS中编译生成test.dll并放置到bin目录的具体命令及参数含义,最后提及testdll.aspx完整调用。

被折叠的 条评论
为什么被折叠?



