?
Solved

GetStoredProcCommand not working.

Posted on 2007-03-27
6
Medium Priority
?
723 Views
Last Modified: 2008-01-09
GetStoredProcCommand not working.

C:\SourceControl_mcupryk\InHouseDev\APPS\MKT0003 - CustomerList\src\CustomerList\App_Code\BOL\Division.vb(261,0): error BC30456: 'GetStoredProcCommand' is not a member of 'CustomerList.DAL.DBAccess'.

C:\SourceControl_mcupryk\InHouseDev\APPS\MKT0003 - CustomerList\src\CustomerList\App_Code\BOL\Division.vb(264,0): error BC30311: Value of type 'System.Data.Common.DbCommand' cannot be converted to 'String'.

Dim db As DAL.DBAccess = New DAL.DBAccess


Try

'We get the divisions

cmd = db.GetStoredProcCommand("PARAM_TWD.dbo.usp_GetDivisions")

'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 objConnectionStringSettings As ConnectionStringSettings = ConfigurationManager.ConnectionStrings("connectionstring")

strConnectionString = objConnectionStringSettings.ConnectionString

Dim cnn As New SqlConnection()

cnn.ConnectionString = strConnectionString

cmd.Connection = cnn

cmd.CommandType = CommandType.StoredProcedure

End Sub

Public Function ExecuteReader() As IDataReader

Dim reader As IDataReader = Nothing

Try

Me.Open()

reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

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
0
Comment
Question by:mathieu_cupryk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 10

Expert Comment

by:Si_Hibbard
ID: 18803166
you have created an instance of an object type DBAccess but the class does not define a method GetStoredProcCommand.

Did you mean to extend another class or interface that impelements this method?
0
 

Author Comment

by:mathieu_cupryk
ID: 18803240
Yes you are right what should I do?
Can you help me create it?
I wish to use the class Namespace Customer.DAL or class DAL

where I need to call sql commands. The above is the only sql commands I have.
I am missing the getstoredproccommand.
0
 
LVL 10

Expert Comment

by:Si_Hibbard
ID: 18803423
does it need to be part of this class?

or just call it were you need to such as

   Database db =
     DatabaseFactory.CreateDatabase();
   //Two operations, one to add the order //and another to add order details
   string sqlCommand = "***commandstring***";
   DbCommand orderCommand =
     db.GetStoredProcCommand(sqlCommand);


or create a new method in the class which does the above
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mathieu_cupryk
ID: 18804629
create a new method in the class which does the above   DbCommand orderCommand =
     db.GetStoredProcCommand(sqlCommand);
0
 

Author Comment

by:mathieu_cupryk
ID: 18805611
I have a class that does all my sql stuff.
I need command GetStoredProcCommand(sqlCommand)
in my class dbaccess
0
 
LVL 10

Accepted Solution

by:
Si_Hibbard earned 2000 total points
ID: 18806776
add a method to your class then. something like this, which is in C# - I do not know the VB syntax

public nnn GetStoredProcCommand(String sqlCommand)
{
Database DbCommand =  DatabaseFactory.CreateDatabase();
DbCommand orderCommand = db.GetStoredProcCommand(sqlCommand);
return orderCommand;
}
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 19 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question