I have the following stored procedure that does not seem to pass the @customer and @contact variable to the sql stored procedure to update a table. The @estnum is working but I cannot understand why the two other variables are not being used in the sql procedure to update a table. When I run this same procedure in sql and provide the parameters there the table is updated correctly. Does anyone see something wrong with my code?
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;
try
{
conn.Open();
cmd.ExecuteNonQuery();
newestLB.Items.Add(Convert.ToString(cmd.Parameters["@newestnum"].Value.ToString()));
}
catch (SqlException err)
{
MessageBox.Show(err.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
conn.Dispose();
}
}
}
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;
try
{
conn.Open();
cmd.ExecuteNonQuery();
newestLB.Items.Add(Convert.ToString(cmd.Parameters["@newestnum"].Value.ToString()));
}
catch (SqlException err)
{
MessageBox.Show(err.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
conn.Dispose();
}
}
}