Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server ASP
|
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 30th, 2004, 07:14 AM
Registered User
 
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Stored procedure IConvertible

I use the following stored procedure to get the UserID. If there is a matching Password and user name then UserId > 0 if not then UserID = 0

CREATE PROCEDURE dbo.spValidateUser(

@MyUserName varchar(50),
@MyPasswordID varchar(50)
)

AS

SELECT UserID FROM UserAccounts
WHERE UserName = @MyUserName
AND PasswordID = @MyPasswordID
GO

And the code is:

SqlCommand mySelect = new SqlCommand("spValidateUser", sqlConnection1);
sqlDataAdapter1.SelectCommand = mySelect;
mySelect.CommandType = CommandType.StoredProcedure;
SqlParameter myParameter = null;

SqlParameter myParameter1 = myParameter1;
//Set parameters for stored procedure

myParameter = mySelect.Parameters.Add("@MyUserName", SqlDbType.VarChar, 50);
myParameter.Value = txtUserName;
myParameter = mySelect.Parameters.Add("@MyPasswordID", SqlDbType.VarChar, 50);
myParameter.Value = txtPassword;

sqlConnection1.Open();

//Get the value
int returnValue = (int) mySelect.ExecuteScalar();
string strA;
//Convert from int to string
strA = Convert.ToString(returnValue);
lblMessage.Text = Convert.ToString(returnValue);

I get the following message:

Exception Details: System.InvalidCastException: Object must implement IConvertible.

Source Error:


Line 186:
Line 187: //Get the value
Line 188: int returnValue = (int) mySelect.ExecuteScalar();
Line 189: string strA;
Line 190: //Convert from int to string


Could you please tell me what im doing wrong???

Regards,

Nick

 
Old November 1st, 2004, 03:22 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hey Nick,

You got to post that on a .Net/C# forum here, to get better response on this. This is an SQL server with Classic ASP forum.

Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure muthu555 SQL Server 2000 1 March 5th, 2007 07:13 AM
Stored Procedure bmains SQL Server ASP 2 October 8th, 2004 03:19 AM
Stored Procedure... babloo81 SQL Server 2000 2 May 1st, 2004 11:25 PM
C# and stored procedure Msmsn C# 1 August 26th, 2003 11:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.