I have the following code to return an id number from a database. It works fine when I run it locally, but when I put the files onto the server, while it does log the data into the DB, but it only returns a 0 and not the ID number.
HHID
is an ID that autoincrements when I log the info to the DB.
SqlConnection conn = new SqlConnection("DB connection stuff");
SqlCommand cmd = conn.CreateCommand();
SqlDataReader reader;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "insert_workshop_requests";
cmd.Parameters.AddWithValue("@HHID", 1);
cmd.Parameters.AddWithValue("@username", usernameData.Text);
cmd.Parameters.AddWithValue("@name", nameData.Text);
cmd.Parameters.AddWithValue("@email", emailData.Text);
cmd.Parameters["@HHID"].Direction = System.Data.ParameterDirection.Output;
try
{
conn.Open();
reader = cmd.ExecuteReader();
HHID = System.Convert.ToInt32(cmd.Parameters["@HHID"].Value);
}
catch (Exception exc)
{
}
finally
{
if (conn.State != ConnectionState.Closed)
conn.Close();
}
This is driving me crazy! Hoping someone can help, because while I've found loads of useful articles about SP that store a 0 rather than an ID, the issues are always when running locally as well. Mine working locally is making it very difficult to debug!
Thanks!