| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 984 人关注过本帖
标题:vb.net读取不同数据的方式(2)
只看楼主 加入收藏
ziyouyu
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-3-12
收藏
 问题点数:0 回复次数:0 
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)
             = 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)
             = 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
搜索更多相关主题的帖子: Microsoft 数据 Dim String 
2008-03-12 13:51
快速回复:vb.net读取不同数据的方式(2)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022947 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved