InvalidCastException Exception

Discussion in '.NET' started by Techy, Jul 12, 2010.

  1. Techy

    Techy

    Joined:
    Jul 12, 2010
    Messages:
    1
    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....
    Techy, Jul 12, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ajit
    Replies:
    1
    Views:
    3,585
    Victor Garcia Aprea [MVP]
    Apr 24, 2004
  2. Floela
    Replies:
    3
    Views:
    564
    Jon Skeet
    Jul 10, 2003
  3. Arjen
    Replies:
    1
    Views:
    7,756
    Carl Prothman [MVP]
    Aug 6, 2003
  4. Miguel Angel Dinelli
    Replies:
    1
    Views:
    442
    Chris Jackson
    Nov 13, 2003
  5. Roy Lawson
    Replies:
    12
    Views:
    5,157
    gdekhayser@voyantinc.com
    Oct 25, 2004
Loading...

Share This Page