mathieu_cupryk
asked on
GetStoredProcCommand need to create in class DBAccess namespace Namespace CustomerList.DAL
GetStoredProcCommand not working.
C:\SourceControl_mcupryk\I nHouseDev\ APPS\MKT00 03 - CustomerList\src\CustomerL ist\App_Co de\BOL\Div ision.vb(2 61,0): error BC30456: 'GetStoredProcCommand' is not a member of 'CustomerList.DAL.DBAccess '.
C:\SourceControl_mcupryk\I nHouseDev\ APPS\MKT00 03 - CustomerList\src\CustomerL ist\App_Co de\BOL\Div ision.vb(2 64,0): error BC30311: Value of type 'System.Data.Common.DbComm and' cannot be converted to 'String'.
Dim db As DAL.DBAccess = New DAL.DBAccess
Try
'We get the divisions
cmd = db.GetStoredProcCommand("P ARAM_TWD.d bo.usp_Get Divisions" )
'Temporarilly put the results in a dataset so we can check for valid data
tmpds = db.ExecuteDataSet(cmd)
'We must ensure that only one table was returned in the execution of the query
If tmpds.Tables.Count.Equals( 1) Then
My module
Namespace CustomerList.DAL
Public Class DBAccess
Private cmd As IDbCommand = New SqlCommand()
Private handleErrors As Boolean = False
Private strLastError As String = ""
Private strConnectionString As String = ""
Public Sub New()
Dim objConnectionStringSetting s As ConnectionStringSettings = ConfigurationManager.Conne ctionStrin gs("connec tionstring ")
strConnectionString = objConnectionStringSetting s.Connecti onString
Dim cnn As New SqlConnection()
cnn.ConnectionString = strConnectionString
cmd.Connection = cnn
cmd.CommandType = CommandType.StoredProcedur e
End Sub
Public Function ExecuteReader() As IDataReader
Dim reader As IDataReader = Nothing
Try
Me.Open()
reader = cmd.ExecuteReader(CommandB ehavior.Cl oseConnect ion)
Catch ex As Exception
If handleErrors Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return reader
End Function
Public Function ExecuteReader(ByVal commandtext As String) As IDataReader
Dim reader As IDataReader = Nothing
Try
cmd.CommandText = commandtext
reader = Me.ExecuteReader()
Catch ex As Exception
If (handleErrors) Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return reader
End Function
Public Function ExecuteScalar() As Object
Dim obj As Object = Nothing
Try
Me.Open()
obj = cmd.ExecuteScalar()
Me.Close()
Catch ex As Exception
If handleErrors Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return obj
End Function
Public Function ExecuteScalar(ByVal commandtext As String) As Object
Dim obj As Object = Nothing
Try
cmd.CommandText = commandtext
obj = Me.ExecuteScalar()
Catch ex As Exception
If (handleErrors) Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return obj
End Function
Public Function ExecuteNonQuery() As Integer
Dim i As Integer = -1
Try
Me.Open()
i = cmd.ExecuteNonQuery()
Me.Close()
Catch ex As Exception
If handleErrors Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return i
End Function
Public Function ExecuteNonQuery(ByVal commandtext As String) As Integer
Dim i As Integer = -1
Try
cmd.CommandText = commandtext
i = Me.ExecuteNonQuery()
Catch ex As Exception
If handleErrors Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return i
End Function
Public Function ExecuteDataSet() As DataSet
Dim da As SqlDataAdapter = Nothing
Dim ds As DataSet = Nothing
Try
da = New SqlDataAdapter()
da.SelectCommand = CType(cmd, SqlCommand)
ds = New DataSet()
da.Fill(ds)
Catch ex As Exception
If (handleErrors) Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return ds
End Function
Public Function ExecuteDataSet(ByVal commandtext As String) As DataSet
Dim ds As DataSet = Nothing
Try
cmd.CommandText = commandtext
ds = Me.ExecuteDataSet()
Catch ex As Exception
If handleErrors Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return ds
End Function
Public Property CommandText() As String
Get
Return cmd.CommandText
End Get
Set(ByVal value As String)
cmd.CommandText = value
cmd.Parameters.Clear()
End Set
End Property
Public ReadOnly Property Parameters() As IDataParameterCollection
Get
Return cmd.Parameters
End Get
End Property
Public Sub AddParameter(ByVal paramname As String, ByVal paramvalue As Object)
Dim param As SqlParameter = New SqlParameter(paramname, paramvalue)
cmd.Parameters.Add(param)
End Sub
Public Sub AddParameter(ByVal param As IDataParameter)
cmd.Parameters.Add(param)
End Sub
Public Property ConnectionString() As String
Get
Return strConnectionString
End Get
Set(ByVal value As String)
strConnectionString = value
End Set
End Property
Private Sub Open()
cmd.Connection.Open()
End Sub
Private Sub Close()
cmd.Connection.Close()
End Sub
Public Property HandleExceptions() As Boolean
Get
Return handleErrors
End Get
Set(ByVal value As Boolean)
handleErrors = value
End Set
End Property
Public ReadOnly Property LastError() As String
Get
Return strLastError
End Get
End Property
Public Sub Dispose()
cmd.Dispose()
End Sub
End Class
End Namespace
I have a class that does all my sql stuff.
I need command GetStoredProcCommand(sqlCo mmand)
in my class dbaccess above
C:\SourceControl_mcupryk\I
C:\SourceControl_mcupryk\I
Dim db As DAL.DBAccess = New DAL.DBAccess
Try
'We get the divisions
cmd = db.GetStoredProcCommand("P
'Temporarilly put the results in a dataset so we can check for valid data
tmpds = db.ExecuteDataSet(cmd)
'We must ensure that only one table was returned in the execution of the query
If tmpds.Tables.Count.Equals(
My module
Namespace CustomerList.DAL
Public Class DBAccess
Private cmd As IDbCommand = New SqlCommand()
Private handleErrors As Boolean = False
Private strLastError As String = ""
Private strConnectionString As String = ""
Public Sub New()
Dim objConnectionStringSetting
strConnectionString = objConnectionStringSetting
Dim cnn As New SqlConnection()
cnn.ConnectionString = strConnectionString
cmd.Connection = cnn
cmd.CommandType = CommandType.StoredProcedur
End Sub
Public Function ExecuteReader() As IDataReader
Dim reader As IDataReader = Nothing
Try
Me.Open()
reader = cmd.ExecuteReader(CommandB
Catch ex As Exception
If handleErrors Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return reader
End Function
Public Function ExecuteReader(ByVal commandtext As String) As IDataReader
Dim reader As IDataReader = Nothing
Try
cmd.CommandText = commandtext
reader = Me.ExecuteReader()
Catch ex As Exception
If (handleErrors) Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return reader
End Function
Public Function ExecuteScalar() As Object
Dim obj As Object = Nothing
Try
Me.Open()
obj = cmd.ExecuteScalar()
Me.Close()
Catch ex As Exception
If handleErrors Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return obj
End Function
Public Function ExecuteScalar(ByVal commandtext As String) As Object
Dim obj As Object = Nothing
Try
cmd.CommandText = commandtext
obj = Me.ExecuteScalar()
Catch ex As Exception
If (handleErrors) Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return obj
End Function
Public Function ExecuteNonQuery() As Integer
Dim i As Integer = -1
Try
Me.Open()
i = cmd.ExecuteNonQuery()
Me.Close()
Catch ex As Exception
If handleErrors Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return i
End Function
Public Function ExecuteNonQuery(ByVal commandtext As String) As Integer
Dim i As Integer = -1
Try
cmd.CommandText = commandtext
i = Me.ExecuteNonQuery()
Catch ex As Exception
If handleErrors Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return i
End Function
Public Function ExecuteDataSet() As DataSet
Dim da As SqlDataAdapter = Nothing
Dim ds As DataSet = Nothing
Try
da = New SqlDataAdapter()
da.SelectCommand = CType(cmd, SqlCommand)
ds = New DataSet()
da.Fill(ds)
Catch ex As Exception
If (handleErrors) Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return ds
End Function
Public Function ExecuteDataSet(ByVal commandtext As String) As DataSet
Dim ds As DataSet = Nothing
Try
cmd.CommandText = commandtext
ds = Me.ExecuteDataSet()
Catch ex As Exception
If handleErrors Then
strLastError = ex.Message
Else
Throw
End If
End Try
Return ds
End Function
Public Property CommandText() As String
Get
Return cmd.CommandText
End Get
Set(ByVal value As String)
cmd.CommandText = value
cmd.Parameters.Clear()
End Set
End Property
Public ReadOnly Property Parameters() As IDataParameterCollection
Get
Return cmd.Parameters
End Get
End Property
Public Sub AddParameter(ByVal paramname As String, ByVal paramvalue As Object)
Dim param As SqlParameter = New SqlParameter(paramname, paramvalue)
cmd.Parameters.Add(param)
End Sub
Public Sub AddParameter(ByVal param As IDataParameter)
cmd.Parameters.Add(param)
End Sub
Public Property ConnectionString() As String
Get
Return strConnectionString
End Get
Set(ByVal value As String)
strConnectionString = value
End Set
End Property
Private Sub Open()
cmd.Connection.Open()
End Sub
Private Sub Close()
cmd.Connection.Close()
End Sub
Public Property HandleExceptions() As Boolean
Get
Return handleErrors
End Get
Set(ByVal value As Boolean)
handleErrors = value
End Set
End Property
Public ReadOnly Property LastError() As String
Get
Return strLastError
End Get
End Property
Public Sub Dispose()
cmd.Dispose()
End Sub
End Class
End Namespace
I have a class that does all my sql stuff.
I need command GetStoredProcCommand(sqlCo
in my class dbaccess above
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.