学习型 ASP/PHP/ASP.NET 主机 30元/年全能 ASP/PHP/ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
发新话题
打印

vb.net读取不同数据的方式(2)

本主题由 静夜思 于 2008-3-12 14:34 拒绝承认原创

vb.net读取不同数据的方式(2)

读取access数据
Shared Function ACCESSOperate(ByVal SQLString As String, ByRef Msg As String) As DataTable
        Try
            Dim CONN As String
            CONN = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=" + Application.StartupPath + "\kctj.mdb"
            Dim oleconn As New OleDb.OleDbConnection(CONN)
            Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(SQLString, oleconn)
            cmd.CommandType = CommandType.Text
            Dim sTokens() As String
            sTokens = SQLString.Split(" ")
            If Strings.InStr("INSERT,DELETE,UPDATE", sTokens(0).ToUpper) Then
                If oleconn.State <> ConnectionState.Open Then
                    oleconn.Open()  '打开数据库连接
                End If
                cmd.ExecuteNonQuery()  '执行SQL语句
                If oleconn.State <> ConnectionState.Closed Then
                    oleconn.Close() '关闭数据库连接
                End If
                If sTokens(0).ToUpper = "INSERT" Then
                    ' MsgBox("插入记录成功")
                End If
                If sTokens(0).ToUpper = "DELETE" Then
                    'MsgBox("删除记录成功")
                End If
                If sTokens(0).ToUpper = "UPDATE" Then
                    'MsgBox("更新记录成功")
                End If
                Return Nothing
            Else
                Dim ObjectdsDataSet As New DataSet()
                Dim adapter As New OleDb.OleDbDataAdapter()
                adapter.TableMappings.Add("Table", "TEMP")
                adapter.SelectCommand = cmd
                If oleconn.State <> ConnectionState.Open Then
                    oleconn.Open()  '打开数据库连接
                End If
                cmd.ExecuteNonQuery()  '执行SQL语句
                If oleconn.State <> ConnectionState.Closed Then
                    oleconn.Close() '关闭数据库连接
                End If
                adapter.Fill(ObjectdsDataSet) '填充数据集
                Return ObjectdsDataSet.Tables("TEMP")
            End If
        Catch
            MsgBox(Err.Description)
        End Try
End Function



读取sql数据
Shared Function SQLOperate(ByVal SQLString As String, ByRef Msg As String) As DataTable
        Try
            Dim CONN As String
            CONN = "Provider=SQLOLEDB;Data Source=192.168.1.49;Initial Catalog='UFDATA_008_2008';User ID='txm1';password='123456'"
            Dim oleconn As New OleDb.OleDbConnection(CONN)
            Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(SQLString, oleconn)
            cmd.CommandType = CommandType.Text
            Dim sTokens() As String
            sTokens = SQLString.Split(" ")
            If Strings.InStr("INSERT,DELETE,UPDATE", sTokens(0).ToUpper) Then
                If oleconn.State <> ConnectionState.Open Then
                    oleconn.Open()  '打开数据库连接
                End If
                cmd.ExecuteNonQuery()  '执行SQL语句
                If oleconn.State <> ConnectionState.Closed Then
                    oleconn.Close() '关闭数据库连接
                End If
                If sTokens(0).ToUpper = "INSERT" Then
                    'MsgBox("插入记录成功")
                End If
                If sTokens(0).ToUpper = "DELETE" Then
                    ' MsgBox("删除记录成功")
                End If
                If sTokens(0).ToUpper = "UPDATE" Then
                    'MsgBox("更新记录成功")
                End If
                Return Nothing
            Else
                Dim ObjectdsDataSet As New DataSet()
                Dim adapter As New OleDb.OleDbDataAdapter()
                adapter.TableMappings.Add("Table", "TEMP")
                adapter.SelectCommand = cmd
                If oleconn.State <> ConnectionState.Open Then
                    oleconn.Open()  '打开数据库连接
                End If
                cmd.ExecuteNonQuery()  '执行SQL语句
                If oleconn.State <> ConnectionState.Closed Then
                    oleconn.Close() '关闭数据库连接
                End If
                adapter.Fill(ObjectdsDataSet) '填充数据集
                Return ObjectdsDataSet.Tables("TEMP")
            End If
        Catch
            MsgBox(Err.Description)
        End Try
    End Function

TOP

发新话题