与vb类中的SQL Server 2008 r2连接 [英] connection with SQL server 2008 r2 in vb class
本文介绍了与vb类中的SQL Server 2008 r2连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请让我知道如何在vb类中进行sql连接,以便在每个页面上我都不必进行sql连接,连接可以通过使用类的对象
Please let me know how can i make sql connection in vb class so that at every page i dont have to make sql connection, connection can become by using object of class
推荐答案
看看这里:
连接字符串和配置文件 [ ^ ]
连接到ASP中的数据库。 NET [ ^ ]
Have a look here:
Connection Strings and Configuration Files[^]
Connecting to Databases in ASP.NET[^]
将连接字符串放在web.config文件中。然后创建一个包含检索连接字符串并返回它的方法的类。
web.config:
Put the connection string in your web.config file. Then create a class that contains methods to retrieve the connection string and return it.
web.config:
<configuration>
<connectionstrings>
<add name="My_ConnectionString" providername="system.data.providername" connectionstring="Server=servername;Database=databasename;Uid=userid;Pwd=password;" />
</connectionstrings>
</configuration>
class:
class:
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.IO
Namespace YourNameSpace
Public Class ConnectionString
Public Function GetConnectionString() As String
Dim DBConnection As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("My_ConnectionString").ConnectionString)
Return DBConnection
End Function
END Class
END Namespace
这是一个非常基本的解决方案,可以给你一个想法。您可能需要调整它才能得到您想要的结果。
This is a very basic solution to give you an idea. You may have to adjust it in order to get what you want.
这篇关于与vb类中的SQL Server 2008 r2连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文