InvalidCastException Exception

Joined
Jul 12, 2010
Messages
1
Reaction score
0
Hi,

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;
conn.Open();
int rows = command.ExecuteNonQuery();//showing error in this line.
conn.Close();


I'm using the following stored procedure

ALTER PROCEDURE dbo.InsertUser

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

AS
INSERT into details VALUES(@FirstName,@SecondName)



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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top