473,407 Members | 2,312 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,407 software developers and data experts.

Can't get a string from SQL query

I've got a stored procedure which works as expected using Run Stored
Procedure in VS.NET:-
-----------------------------------------------------------
ALTER PROCEDURE dbo.ValidateUser
@Username nVarChar(50),
@Password nVarChar(24),
@Valid nvarchar(36) OUTPUT
as
Select @Valid=cast(UserID as nvarchar(36)) From userdata
Where Username=@Username
and Password=@Password
-----------------------------------------------------------

UserID is a uniqueIdentifier.

But I can't get a value from @Valid in VB.NET using an output paramater,
it's always an empty string:-
-----------------------------------------------------------
Private sqlConnectionString As String =
ConfigurationSettings.AppSettings("sqlConnectionSt ring")

Public Function validateUser(ByVal nam As String, ByVal pwd As String) As
String
Dim sqlCmd As New SqlCommand("validateUser", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure

Dim sqlParam As New SqlParameter("@UserName", SqlDbType.NVarChar)
sqlParam.Value = Trim(nam)
sqlCmd.Parameters.Add(sqlParam)

sqlParam = New SqlParameter("@Password", SqlDbType.NVarChar)
sqlParam.Value = Trim(pwd)
sqlCmd.Parameters.Add(sqlParam)

Dim sqlParamUserID As New SqlParameter("@Valid", SqlDbType.NVarChar)
sqlParamUserID.Value = ""
sqlParamUserID.Direction = ParameterDirection.Output
sqlCmd.Parameters.Add(sqlParamUserID)

Try
If sqlConn.State <> ConnectionState.Open Then
sqlConn.Open()
End If
sqlCmd.ExecuteReader()
Catch e As Exception
Throw e
End Try

sqlConn.Close()

Return CType(sqlParamUserID.Value, String)
End Function
-----------------------------------------------------------

However, if I change the stored procedure to return an int (e.g. select
@Valid=count(*) ), and change the VB to expect a number then it does work.

What am I doing wrong?

Andrew
Nov 22 '05 #1
1 1347
Andrew Morton wrote:
ALTER PROCEDURE dbo.ValidateUser
@Username nVarChar(50),
<snip>
Dim sqlParam As New SqlParameter("@UserName", SqlDbType.NVarChar)


Solution: use the size parameter, as in
Dim sqlParam As New SqlParameter("@UserName", SqlDbType.NVarChar, 50)

Andrew
Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
5
by: Mart | last post by:
Hi everybody, I plan to have a LOT of SQL string in my app. So I need your advice for this. Is it a good idea to store all my SQL string in the app.config file? For a maintenance point of...
2
by: Greg Schumacher | last post by:
Running PHP v5.0.4 (compiled by www.entropy.ch) and mysql 5.0.16 on Mac OS X 10.4.3. When I run the simple test script below the first query sent from PHP to MySQL is successful but the second is...
18
by: William | last post by:
I have the following javascript function that updates a scroll_list and sends the updated entry (with its index) to a server script ( i.e. http://mkmxg00/cgi/confirmUpload.pl ) for further...
2
by: Robert | last post by:
I am trying to give the user dynamic search capabilities to select almost any record in the database from criteria they select. Everything seems to work except when I open the display form to...
11
by: whulling | last post by:
I have been coding for a while, and admittedly am a bit of a hack / learn as you go type of person, so I am sure this code is not pretty, any help would be greatly appreciated, I've been stuck for a...
3
by: jwgoerlich | last post by:
Hello group, I am working on a query string class. The purpose is to parse name-value pairs from incoming text. Currently, I am using the Regex code below. I have two questions. First, the...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
3
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one...
3
bilibytes
by: bilibytes | last post by:
Hi, I am having a problem with a concatenated string. I start my string outside of a for() and then, concatenate the string generated with the loop to it. the string out of the loop looks like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.