InvalidCastException

Discussion in 'General Computer Support' 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

  2. Techy

    sunnyye

    Joined:
    Jul 13, 2010
    Messages:
    3
    For you answer ,I have some suggestion. Maybe you can try this, and have a look,
    coachhandbagstrade free shipping, paypal accepted.
    sunnyye, Jul 13, 2010
    #2
    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.

Share This Page