ITPub博客

首页 > 数据库 > 数据库开发技术 > 解决一个.NET联接SQL的问题 (转)

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

原创 数据库开发技术 作者:amyz 时间:2007-10-17 18:37:03 0 删除 编辑
解决一个.NET联接SQL的问题 (转)[@more@]

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


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752019/viewspace-977242/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    3984
  • 访问量
    7371803