我建的了一dbsql.vb类,可是别的文件怎么引用他啊。
Imports System.Data
Imports System.Data.SqlClient
Public Class SQLDB
Private ServerName As String
Private DatabaseName As String
Private UserName As String
Private UserPassword As String
Private cnn As SqlConnection
'构造函数
Public Sub New()
MyBase.new()
ServerName = "localhost"
UserName = "sa"
UserPassword = "sa"
End Sub
Public Sub New(ByVal server As String, ByVal database As String, ByVal uid As String, ByVal pwd As String)
ServerName = server
DatabaseName = database
UserName = uid
UserPassword = pwd
End Sub
Public Function open(ByRef msg As String) As Boolean
cnn = New SqlConnection
Dim cnnstr As String = "data source=" + ServerName + "; initial catalog=" + DatabaseName + "; user id=" + UserName + "; pwd=" + UserPassword
cnn.ConnectionString = cnnstr
Try
cnn.Open()
Catch ex As Exception
msg = ex.Message
Return False
End Try
Return True
End Function
Public Function SelectDB(ByVal sql As String, ByRef msg As String) As DataSet
Dim ds As DataSet
ds = New DataSet
Try
If cnn.State = ConnectionState.Closed Then
cnn.Open()
End If
Dim da As SqlDataAdapter = New SqlDataAdapter(sql, cnn)
da.Fill(ds)
cnn.Close()
Catch ex As Exception
msg = ex.Message
ds = Nothing
Return ds
End Try
Return ds
End Function
Public Function UpadateDB(ByVal sql As String, ByRef msg As String) As Boolean
Dim cma As SqlCommand = New SqlCommand
Try
If cnn.State = ConnectionState.Closed Then
cnn.Open()
End If
cma.Connection = cnn
cma.CommandText = sql
cma.CommandType = CommandType.Text
cma.ExecuteNonQuery()
cnn.Close()
Catch ex As Exception
msg = ex.Message
Return False
End Try
Return True
End Function
End Class
--------------------编程问答-------------------- 直接加入工程
或
生成为dll,别的工程引用
--------------------编程问答-------------------- 大学毕业论文用的是VB
看着好亲切,呵呵 --------------------编程问答-------------------- up --------------------编程问答-------------------- 有点急添加引用 --------------------编程问答-------------------- 如果在同一个namespace下,直接将文件添加进去就可以被应用了
也可以编译成dll进行引用 --------------------编程问答-------------------- 怎么把这个.vb设置在同一个namespace下啊。 --------------------编程问答-------------------- 别的文件怎么引用?
补充:.NET技术 , ASP.NET