Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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:07 AM
Registered User
 
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Stored procedure IConvertible

 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






Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure muthu555 SQL Server 2000 1 March 5th, 2007 07:13 AM
Stored procedure IConvertible nk15 SQL Server ASP 1 November 1st, 2004 03:22 PM
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.