473,397 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

SQL Stored Procedures and VB.NET

38
Hey there!

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
  1.         Try
  2.             Dim cmdVideoCount As New SqlCommand
  3.             cmdVideoCount.Connection = sqlConn
  4.             cmdVideoCount.CommandText = "GetVideoCount"
  5.             cmdVideoCount.CommandType = CommandType.StoredProcedure
  6.  
  7.             Dim paramResult As New SqlParameter
  8.             paramResult.ParameterName = "@VideoCount"
  9.             paramResult.DbType = DbType.Int16
  10.             paramResult.Direction = ParameterDirection.Output
  11.             cmdVideoCount.Parameters.Add(paramResult)
  12.  
  13.             sqlConn.Open()
  14.             Dim intVideos As Integer = cmdVideoCount.ExecuteScalar()
  15.             MsgBox(intVideos)
  16.             sqlConn.Close()
  17.         Catch ex As Exception
  18.             Throw ex
  19.         Finally
  20.             sqlConn.Close()
  21.         End Try
  22.  
The code for the stored procedure is:
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE GetVideoCount ( @VideoCount int OUTPUT )
  2. AS
  3. SELECT @VideoCount = Count(Video_ID) FROM Videos
  4. GO
  5.  
At the moment, it has now stopped raining, yay! and the stored procedure returns 0.

There is one test record in the database at the moment.

Any help would be appreciated, thanks.

Enyi
Jul 31 '06 #1
2 12347
change the procedure
from

CREATE PROCEDURE GetVideoCount ( @VideoCount int OUTPUT )
AS
SELECT @VideoCount = Count(Video_ID) FROM Videos
GO

to

CREATE PROCEDURE GetVideoCount ( )
AS
SELECT Count(Video_ID) FROM Videos
GO

and remove the following lines from your code
Dim paramResult As New SqlParameter
paramResult.ParameterName = "@VideoCount"
paramResult.DbType = DbType.Int16
paramResult.Direction = ParameterDirection.Output
cmdVideoCount.Parameters.Add(paramResult)

ExecuteScalar returns the first field of the first record as an object.
in your case the Count(Video_ID) is returned from the call to ExecuteScalar
Jul 31 '06 #2
Enyi
38
Thank you very much. Had been getting annoyed with this code. The procedure and code makes a bit more sense now. Thanks.
Aug 1 '06 #3

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

Similar topics

11
by: jrefactors | last post by:
I want to know the differences between SQL Server 2000 stored procedures and oracle stored procedures? Do they have different syntax? The concept should be the same that the stored procedures...
2
by: scott | last post by:
Hi, Just wondering what sort of problems and advantages people have found using stored procedures. I have an app developed in VB6 & VB.NET and our developers are starting to re-write some of the...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
5
by: Rhino | last post by:
I am trying to determine the behaviour of stored procedures in DB2 V8.2.x in Windows/Unix/Linux and how I can control that behaviour. Some documentation in the manuals is confusing the issue...
5
by: Tim Marshall | last post by:
I was following the thread "Re: Access Treeview - Is it Safe Yet?" with interest and on reading the post describing Lauren Quantrell's SmartTree, I've run into something I don't understand: Stored...
2
by: Eli | last post by:
Hi all We currently have a strange problem with calling a Stored Procedure (SQL Database) in our C# Project. The only error I get is "System error" which says a lot :) Background: We have...
0
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how...
45
by: John | last post by:
Hi When developing vb.bet winform apps bound to sql server datasource, is it preferable to use SELECTs or stored procedure to read and write data from/to SQL Server? Why? Thanks Regards
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
11
by: peter | last post by:
I am trying to get a SQL stored procedure to use user maintained MQT implicitly which raises questions on when they are used or not used. In theory you would expect the stored procedure to pick up...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.