解決一個.NET聯接SQL的問題 (轉)

amyz發表於2007-10-17
解決一個.NET聯接SQL的問題 (轉)[@more@]

Imports System.Data
Imports System.Data.Client
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;pass=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 As New DataSet()

  Dim ada As New SqlDataAdapter()
  Dim com1 As New SqlCommand()
  com1.Connection = Connect
  com1.CommandText = s
  ada.Command = 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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章