I need some help getting some code to work. This particular bit is nearly done, just that it's not working.
Situation:
Trying to get the row count of an table in an SQL database using VB.NET 2003 and stored procedures in SQL Server 2000 Developer Edition. Dam, it's also just started to rain, oh dear. Anyways...
Somewhere in my project is the code:
Expand|Select|Wrap|Line Numbers
- Try
- Dim cmdVideoCount As New SqlCommand
- cmdVideoCount.Connection = sqlConn
- cmdVideoCount.CommandText = "GetVideoCount"
- cmdVideoCount.CommandType = CommandType.StoredProcedure
- Dim paramResult As New SqlParameter
- paramResult.ParameterName = "@VideoCount"
- paramResult.DbType = DbType.Int16
- paramResult.Direction = ParameterDirection.Output
- cmdVideoCount.Parameters.Add(paramResult)
- sqlConn.Open()
- Dim intVideos As Integer = cmdVideoCount.ExecuteScalar()
- MsgBox(intVideos)
- sqlConn.Close()
- Catch ex As Exception
- Throw ex
- Finally
- sqlConn.Close()
- End Try
Expand|Select|Wrap|Line Numbers
- CREATE PROCEDURE GetVideoCount ( @VideoCount int OUTPUT )
- AS
- SELECT @VideoCount = Count(Video_ID) FROM Videos
- GO
There is one test record in the database at the moment.
Any help would be appreciated, thanks.
Enyi