By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,996 Members | 1,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,996 IT Pros & Developers. It's quick & easy.

command.CommandTimeout

P: 2
Can someone please help me? I have class for database connection and I need set command.commandTimeout. How can I do that?

Code:
Imports System.Data.SqlClient
Imports System.Data
Public Class Db
Private Shared _ConnString As String = ""
Private Shared _Connection As SqlConnection

Public Shared Sub SetConnectionString(ByVal connString As String)
_ConnString = connString
End Sub

Public Shared Function GetReader(ByVal sqlStatement As String, ByVal params() As Object) As SqlDataReader
OpenConnection()
Dim command As SqlCommand
command = FillParams(sqlStatement, params)
Return command.ExecuteReader(CommandBehavior.CloseConnect ion)
End Function

Public Shared Function GetDataSet(ByVal sqlStatement As String) As DataSet
Dim retDs As New DataSet
OpenConnection()
Dim ad As New SqlDataAdapter(sqlStatement, _Connection)
ad.Fill(retDs)
_Connection.Close()
Return retDs
End Function

Public Shared Function Exec(ByVal sqlStatement As String, ByVal params() As Object, ByVal maOutput As Boolean) As ArrayList
Dim ret As ArrayList = New ArrayList
OpenConnection()
Dim command As SqlCommand

command = FillParams(sqlStatement, params)
command.ExecuteNonQuery()
For Each p As SqlParameter In command.Parameters
If p.Direction = ParameterDirection.InputOutput Or p.Direction = ParameterDirection.Output Then
Try
ret.Add(p.Value)
Catch : End Try
End If
Next
Return ret
End Function

Public Shared Function execCom(ByVal sqlStatement As String, ByVal params() As Object) As Int32
OpenConnection()
Dim command As SqlCommand

command = FillParams(sqlStatement, params)

Return command.ExecuteNonQuery()
End Function

Private Shared Function FillParams(ByVal sqlStatement As String, ByVal params() As Object) As SqlCommand
Dim command As New SqlCommand(sqlStatement, _Connection)


If Not params Is Nothing Then
Dim i As Int16
For i = 0 To params.Length - 1
command.Parameters.Add(CType(params(i), SqlParameter))
Next
End If
Return command
End Function

Private Shared Sub OpenConnection()
If _Connection Is Nothing Then
_Connection = New SqlConnection(_ConnString)
End If

If Not _Connection.State = ConnectionState.Open Then
_Connection.Open()
Else
_Connection.Close()
_Connection.Open()
End If
End Sub


End Class
Sep 3 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.