我执行并插入新记录,此代码适用于插入。之后,我想使用window.parent.location重定向到另一个页面,其中包含我在插入中使用的ID(ProposalID)。
private void ExecuteInsert(string ProposedID, string CreatedBy, string Note)
{
SqlConnection conn = new SqlConnection(GetConnectionString());
string sql = "INSERT INTO MDF_ProposedNote (ProposedID, Note, CreatedBy)
VALUES "
+ " (@ProposedID, @Note, @CreatedBy)";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter[] param = new SqlParameter[3];
param[0] = new SqlParameter("@ProposedID", SqlDbType.Int, 10);
param[1] = new SqlParameter("@Note", SqlDbType.VarChar, 2000);
param[2] = new SqlParameter("@CreatedBy", SqlDbType.Int, 10);
param[0].Value = ProposedID;
param[1].Value = Note;
param[2].Value = CreatedBy;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
Response.Write("<script>window.parent.location =
'ProposalItemView.aspx?ProposedID='"<%=ProposedID%>";</script>");
}
}
这是我和重定向到另一个页面+ RecordID
的地方Response.Write("<script>window.parent.location =
'ProposalItemView.aspx?ProposedID='"<%=ProposedID%>";</script>");
请帮忙。提前谢谢。
答案 0 :(得分:3)
你可能想要
Response.Redirect(string.format("~/ProposalItemView.aspx?ProposedID={0}", ProposedID), true);