Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > General Computer Support > InvalidCastException

Thread Tools


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
sunnyye sunnyye is offline
Junior Member
Join Date: Jul 2010
Posts: 3
For you answer ,I have some suggestion. Maybe you can try this, and have a look,
coachhandbagstrade free shipping, paypal accepted.
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
"System.InvalidCastException: Specified cast is not valid." during Roy Lawson ASP .Net 12 10-25-2004 05:42 PM
User Control - InvalidCastException: Specified cast is not valid Ajit ASP .Net 1 04-24-2004 09:28 PM
PRB: Error Message: System.InvalidCastException: Specified Cast Is Not Valid Miguel Angel Dinelli ASP .Net 1 11-13-2003 07:56 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