我用这段代码连接数据库
Imports System.Data
Imports System.Data.SqlClient
Public Class SQLClass1
Inherits System.Data.SqlClient.SQLDebugging
Public Shared Connstr As String = "server=localhost;database=Northwind;uid=sa;pwd="
Public Function CreateDataTable(ByVal SQLcmd As String) As DataTable
Dim conn As SqlConnection
Dim myadapter As SqlDataAdapter
Dim myaDataset As New DataSet
Try
conn = New SqlConnection(Connstr)
conn.Open() '打开数据库连接
myadapter = New SqlDataAdapter(SQLcmd, conn) '执行SQLcmd语句
myadapter.Fill(myaDataset) '将结果填充到myaDataset数据集中
conn.Close() '操作完成后关闭数据库连接
Return myaDataset.Tables(0) '返回数据集中的数据表
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
多个form要连接数据库,在form1中要执行删除,在form2执行增加。怎么实现。。。
[此贴子已经被作者于2006-12-9 22:36:01编辑过]