Need help on passing id to next page on response.redirect
-
I am inserting into the database and want to pass the id to the next page via response.redirect but am not sure how to do that. Here is the code I have:
string custsrc = custsrccode.Text;
string name = custname.Text;
string city = custcity.Text;
string state = custstate.Text;
string postcode = custpostalcode.Text;
string actcode = activitycode.SelectedItem.Text;
string id = labelID.Text;
string activityid = labelactivityid.Text;OracleConnection conn = new OracleConnection(); // C#
conn.ConnectionString = strConnection;
conn.Open();OracleCommand cmd = new OracleCommand(); cmd.Connection = conn; cmd.CommandText = "INSERT INTO BUYING\_ACTIVITY (CUSTOMER\_SOURCE\_CODE, CUSTOMER\_NAME, CUSTOMER\_CITY, CUSTOMER\_STATE, CUSTOMER\_POSTAL\_CODE, BUYING\_ACTIVITY\_CODE, ID) " + "VALUES (:custsrc, :name, :city, :state, :postcode, :actcode, :id)"; cmd.Parameters.Add(new OracleParameter("custsrc", custsrc)); cmd.Parameters.Add(new OracleParameter("name", name)); cmd.Parameters.Add(new OracleParameter("city", city)); cmd.Parameters.Add(new OracleParameter("state", state)); cmd.Parameters.Add(new OracleParameter("postcode", postcode)); cmd.Parameters.Add(new OracleParameter("actcode", actcode)); cmd.Parameters.Add(new OracleParameter("id", id)); cmd.ExecuteNonQuery(); conn.Close();
Response.Redirect("contractinfo.aspx?Id=" + labelRID.Text);
I get nothing on the labelID.Text when I step thru my code and then when it goes to the next page I obviously get nothing as well contractinfo.aspx?Id="" where the "" should be the id value. How do I fix this with the code I have.
-
I am inserting into the database and want to pass the id to the next page via response.redirect but am not sure how to do that. Here is the code I have:
string custsrc = custsrccode.Text;
string name = custname.Text;
string city = custcity.Text;
string state = custstate.Text;
string postcode = custpostalcode.Text;
string actcode = activitycode.SelectedItem.Text;
string id = labelID.Text;
string activityid = labelactivityid.Text;OracleConnection conn = new OracleConnection(); // C#
conn.ConnectionString = strConnection;
conn.Open();OracleCommand cmd = new OracleCommand(); cmd.Connection = conn; cmd.CommandText = "INSERT INTO BUYING\_ACTIVITY (CUSTOMER\_SOURCE\_CODE, CUSTOMER\_NAME, CUSTOMER\_CITY, CUSTOMER\_STATE, CUSTOMER\_POSTAL\_CODE, BUYING\_ACTIVITY\_CODE, ID) " + "VALUES (:custsrc, :name, :city, :state, :postcode, :actcode, :id)"; cmd.Parameters.Add(new OracleParameter("custsrc", custsrc)); cmd.Parameters.Add(new OracleParameter("name", name)); cmd.Parameters.Add(new OracleParameter("city", city)); cmd.Parameters.Add(new OracleParameter("state", state)); cmd.Parameters.Add(new OracleParameter("postcode", postcode)); cmd.Parameters.Add(new OracleParameter("actcode", actcode)); cmd.Parameters.Add(new OracleParameter("id", id)); cmd.ExecuteNonQuery(); conn.Close();
Response.Redirect("contractinfo.aspx?Id=" + labelRID.Text);
I get nothing on the labelID.Text when I step thru my code and then when it goes to the next page I obviously get nothing as well contractinfo.aspx?Id="" where the "" should be the id value. How do I fix this with the code I have.
You read the id from labelID
string id = labelID.Text;
But the ID you are passing on the query string is labelRID
Response.Redirect("contractinfo.aspx?Id=" + labelRID.Text);
If it's the same id use the same label, or just re-use the id variable
Response.Redirect("contractinfo.aspx?Id=" + id);