15-07-17, 01:15 PM
(آخر تعديل لهذه المشاركة : 15-07-17, 01:23 PM {2} بواسطة silverlight.)
لست خبير قواعد بيانات
لكن ربما الكلاس التالي يساعدك
الإستخدام
او استخدم الكلاس كما يحلو لك أكيد أنت أكثر خبرة مني في قواعد البيانات
متهيألي تقدر تكتب كل أوامر الاستعلام في الكلاس
وتنفذها مرة واحدة
لكن ربما الكلاس التالي يساعدك
PHP كود :
Imports System.Data.SqlClient
Public Class CairoConnection
Implements IDisposable
Private _disposed As Boolean
Private _conn As SqlConnection
Private _command As SqlCommand
Public Sub New(connectionString As String)
_conn = New SqlConnection(connectionString)
_command = New SqlCommand
End Sub
Public ReadOnly Property Connection As SqlConnection
Get
Return _conn
End Get
End Property
Public ReadOnly Property Command As SqlCommand
Get
Return _command
End Get
End Property
Private Sub CloseConnection()
_conn.Close()
End Sub
Private Sub DisposeSqlObjects()
CloseConnection()
If _conn IsNot Nothing Then
_conn.Dispose()
_conn = Nothing
End If
If _command IsNot Nothing Then
_command.Dispose()
_command = Nothing
End If
End Sub
Protected Overridable Sub Dispose(disposing As Boolean)
If _disposed Then
Return
End If
If disposing Then
DisposeSqlObjects()
End If
_disposed = True
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
' GC.SuppressFinalize(Me)
End Sub
End Class
الإستخدام
او استخدم الكلاس كما يحلو لك أكيد أنت أكثر خبرة مني في قواعد البيانات
PHP كود :
Dim s As String = "Your Connection" ' read connection from ConfigurationManager
Using conn As New CairoConnection(s)
' do something
Dim queryString As String = "any query String"
conn.Connection.Open()
conn.Command.CommandText = queryString
conn.Command.CommandType = CommandType.Text
conn.Command.ExecuteNonQuery()
End Using
وتنفذها مرة واحدة

