Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > InvalidCastException Exception

Thread Tools

InvalidCastException Exception

Techy Techy is offline
Junior Member
Join Date: Jul 2010
Posts: 2

I'm new to .NET.

when I 'm trying to execute the following code I got an InvalidCastException error

string FirstName = "txtFirstName";// get username from user
string SecondName = "txtSecondName" ;// get password from user
SqlConnection conn = new SqlConnection("Data Source=localhost;Database=db2;Integrated Security=SSPI");
SqlCommand command = new SqlCommand("InsertUser", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = txtFirstName;
command.Parameters.Add("@SecondName", SqlDbType.VarChar).Value = txtSecondName;
int rows = command.ExecuteNonQuery();//showing error in this line.

I'm using the following stored procedure


@FirstName varchar(50),
@SecondName varchar(50)

INSERT into details VALUES(@FirstName,@SecondName)

What is causing this error? What can I do? Can anyone help me....
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
User Control - InvalidCastException: Specified cast is not valid Ajit ASP .Net 1 04-24-2004 09:28 PM
System.InvalidCastException: Specified cast is not valid. Arjen ASP .Net 1 08-06-2003 03:26 AM
System.InvalidCastException: Specified cast is not valid Floela ASP .Net 3 07-10-2003 10:36 AM