首页 > 编程 > .NET > 正文

解决一个.NET联接SQL的问题 yiyang(转贴)

2024-07-10 13:02:46
字体:
来源:转载
供稿:网友
  • 网站运营seo文章大全
  • 提供全面的站长运营经验及seo技术!
  • 解决一个.net联接sql的问题    yiyang(转贴)  
      
    关键字     .net
      
    出处     http://ouynagouyang
      


    imports system.data
    imports system.data.sqlclient
    imports system.data.sqlclient.sqlexception
    public class connect
        private s as string
        private s1 as string
        public connect as new sqlconnection("server=yiyang;database=kderp;uid=sa;password=123")
        sub new()
            connect.open()
        end sub
        public property sql()
            get
                return s
            end get
            set(byval value)
                s = value
            end set
        end property
        'public property table()
        '    get
        '        return s1
        '    end get
        '    set(byval value)
        '        s1 = value

        'end property
        public function retable() as datatable

            dim com as new dataset()

            dim ada as new sqldataadapter()
            dim com1 as new sqlcommand()
            com1.connection = connect
            com1.commandtext = s
            ada.selectcommand = com1
            ada.fill(com, "t1")
            return com.tables(0)

        end function
        public function exec() as integer
            dim i as integer

            dim com as new sqlcommand()
            com.commandtext = s
            com.connection = connect
            i = com.executenonquery()
            return i
        end function
        public function retdataset(byval t as string) as dataset

            dim com as new sqlcommand()
            com.connection = connect
            com.commandtext = s
            dim ada as new sqldataadapter()
            ada.selectcommand = com
            dim da as new dataset()
            ada.fill(da, t)
            return da
        end function
        public function retdataread() as sqldatareader

            dim com as new sqlcommand()
            com.connection = connect
            com.commandtext = s
            return com.executereader
        end function
    end class



    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表