salvationishere
salvationishere

Reputation: 3511

vb error: Value of type 'String' cannot be converted to 'System.Data.SqlClient.SqlCommand'

I'm a novice VB programmer and I'm sure this solution is trivial, however, I am getting the above error when I try to display the results of one of my Stored Procs in SQL Server which doesn't need any parameters. How can I fix this?

My code excerpt:

Dim SQLCmd as SQLCommand = new SQLCommand()
SQLCmd.CommandText = "Exec AllTableCount" 
SQLCmd.CommandType = CommandType.StoredProcedure 
SQLCmd.Connection = GlobalFunctions.GlobalF.GetDevSQLServerStoredProcedure(SQLCmd.CommandType)             
SQLCmd.ExecuteNonQuery()
MsgBox(SQLCmd.ExecuteNonQuery)

Where GetDevSQLServerStoredProcedure is defined in a different file as:

Public Shared Function GetDevSQLServerStoredProcedure(ByVal SQL As String)
   Dim DBConn As SQLConnection
   Dim DBCommand As SQLDataAdapter
   Dim DSPageData As New System.Data.DataSet
   DBConn = New SQLConnection(ConfigurationSettings.AppSettings("AMDMetricsDevConnectionString"))
   DBCommand = New SQLDataAdapter(SQL) 'This is the line it errors on'
   DBCommand.Fill(DSPageData, "Exceptions")
   Return DSPageData
End Function

I can see this SP from VS 2008 in the Server Explorer. So the problem seems to be that I don't know how to connect a data adapter to an SP. Just a string query.

Upvotes: 0

Views: 3163

Answers (1)

Craig
Craig

Reputation: 7076

Command text should just be the name of the stored procedure as Tim mentioned.

It looks like the problem you are having now is that you are passinging the CommandType to your method GetDevSQLServerStoredProcedure instead of a string.

Upvotes: 1

Related Questions