I have a stored procedure which returns a parameter @quotenum when run in sql but I'm having trouble getting a return value in my C# form. I'm trying to get the message box to show the @quoteno parameter but im failing misserably. The connection is working an the parameter @estnum is being passed but Im having trouble with the code to pick up the return value. ANy help correcting this code would be appreciated.
private void approveestBN_Click(object sender, EventArgs e)
{
{
int estno;
int endestno;
int.TryParse(endTB.Text, out endestno);
int quoteno =0;
int @quotenum =0;
if (int.TryParse(startestnoCB.Text, out estno))
while (estno <= endestno)
{
SqlConnection conn = new SqlConnection("Data Source=server1;Initial Catalog=estimator;Integrated Security=True");
SqlCommand cmd = new SqlCommand("QuoteCreate", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@estnum", estno);
cmd.Parameters.AddWithValue("@quotenum",quoteno);
try
{
conn.Open();
//cmd.ExecuteNonQuery(); // If you do not need a return;
cmd.ExecuteScalar();
quoteno = @quotenum";
MessageBox.Show(Convert.ToString(quoteno));
estno = estno + 1;
}
catch (SqlException err)
{
MessageBox.Show(err.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
conn.Dispose();
}
}
}
}