I have the following code that executes an sql stored procedure and I pass a customer name and customer contact to the procedure to use to create a new record in a table. When I execute the stored procedure in sql it inputs the customer and contact in the new record but when I use the following code it creates a new record but the customer and contact are blank. Can anyone see what I have done wrong. Here is my code. Thanks in advance.

private void copyestBN_Click(object sender, EventArgs e)
            int estno;
            char customer;
            char contact;
            char.TryParse(customercopyCB.Text, out customer);
            char.TryParse(newcontactTB.Text, out contact);
            int.TryParse(estimatenocopyCB.Text, out estno);

                SqlConnection conn = new SqlConnection("Data Source=server1;Initial Catalog=estimator;Integrated Security=True");
                SqlCommand cmd = new SqlCommand("copyestimate", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@estnum", estno);
                cmd.Parameters.AddWithValue("@customer", customer);
                cmd.Parameters.AddWithValue("@contact", contact);
                cmd.Parameters.AddWithValue("@newestnum", SqlDbType.Int).Direction = ParameterDirection.Output;


                catch (SqlException err)
                    if (conn.State == ConnectionState.Open)

dont cast those strings to char
especially if is not a char[] array... hint

just send the text of the components into the parameter assignment.

cmd.Parameters.AddWithValue("@customer", customercopyCB.Text);
This article has been dead for over six months. Start a new discussion instead.