Sql数据库改成Access数据库后,连接字符串和打开数据库、查询数据库怎么修改
Imports System.Collections.GenericImports System.TextImports System.DataImports System.Data.SqlClientImports System.Windows.FormsNamespace SoftSystem.Common Class DATA#Region "全局变量" Public Shared Login_Num As String Public Shared Login_Name As String Public Shared MyData_con As SqlConnection Public Shared MyData_Mydb As String = "Data Source=MyDateBase;Database=softSystem;User=sa;PWD=as" Public Shared msg As String() = New String(4) {"添加", "删除", "修改", "借阅", "归还"}#End Region Public Shared Function GetConnection() As SqlConnection MyData_con = New SqlConnection(MyData_Mydb) MyData_con.Open() Return MyData_con End Function Public Shared Sub CloseConnection() If MyData_con.State = ConnectionState.Open Then MyData_con.Close() MyData_con.Dispose() End If End Sub Public Shared Function GetCommand(ByVal str_SQL As String) As SqlDataReader GetConnection() Dim MyData_com As SqlCommand = MyData_con.CreateCommand() MyData_com.CommandText = str_SQL Dim MyData_read As SqlDataReader = MyData_com.ExecuteReader() Return MyData_read End Function Public Shared Sub GetSQLCommand(ByVal str_SQL As String, ByVal OperCode As Integer, ByVal showmsg As Boolean) GetConnection() Dim MyData_SQLcom As New SqlCommand(str_SQL, MyData_con) Try If MyData_SQLcom.ExecuteNonQuery() > 0 Then If showmsg Then MessageBox.Show(msg(OperCode) & "成功!", "提示信息") End If Else If showmsg Then MessageBox.Show(msg(OperCode) & "失败!", "提示信息") End If End If MyData_SQLcom.Dispose() CloseConnection() Return Catch e As Exception MessageBox.Show(msg(OperCode) & "失败!" & vbLf & "出错原因:" & e.Message, "提示信息") End Try MyData_SQLcom.Dispose() CloseConnection() End Sub Public Shared Sub GetSQLCommand(ByVal str_SQL As String(), ByVal OperCode As Integer, ByVal showmsg As Boolean) GetConnection() Dim MyData_SQLcom As New SqlCommand() Dim MyData_tran As SqlTransaction MyData_tran = MyData_con.BeginTransaction() MyData_SQLcom.Connection = MyData_con MyData_SQLcom.Transaction = MyData_tran Try For i As Integer = 0 To str_SQL.Length - 1 If str_SQL(i) = "" Then Continue For End If MyData_SQLcom.CommandText = str_SQL(i) MyData_SQLcom.ExecuteNonQuery() Next MyData_tran.Commit() If showmsg Then MessageBox.Show(msg(OperCode) & "成功!", "提示信息") End If Catch e As Exception MyData_tran.Rollback() If showmsg Then MessageBox.Show(msg(OperCode) & "失败!" & vbLf & "出错原因:" & e.Message, "提示信息") End If End Try MyData_SQLcom.Dispose() CloseConnection() End Sub Public Shared Sub DataGVBind(ByVal gv As DataGridView, ByVal str_SQL As String) MyData_con = GetConnection() Dim sda As New SqlDataAdapter(str_SQL, MyData_con) Dim ds As New DataSet() sda.Fill(ds) gv.DataSource = ds.Tables(0) End Sub End ClassEnd Namespace