I am attempting to set the value ofa hidden field to the value of the the primary key for the record the user inserts. I will then use this to implement another Insert Into statement, but I am unable to get the output into the hidden field "hdn_doc_id_2". The parameter I am trying to use to capture the output is @docIdPk.
Here is what I tried to use, but haven't been successful:
protected void newDocUpldBtn_Click(object sender, EventArgs e)
{
//Save the file to the server and set the full path
int i = 0;
FileUpload fu = docFU;
string filename = fu.FileName;
string fnnnoext = System.IO.Path.GetFileNameWithoutExtension(fu.FileName);
string fnnextonly = System.IO.Path.GetExtension(fu.FileName);
if (fu.HasFile)
{
while (System.IO.File.Exists(Server.MapPath("~/Data/") + filename))
{
i++;
filename = (fnnnoext + "(" + i.ToString() + ")" + fnnextonly);
}
fu.PostedFile.SaveAs(Server.MapPath("~/Data/") + filename);
hdn_doc_path.Value = (Server.MapPath("~/Data/") + filename);
hdn_doc_path_no_ext.Value = (fnnnoext + "(" + i.ToString() + ")" + fnnextonly);
SqlConnection drap_cnxn = new SqlConnection("Data Source=WDBSVCPRD01\\SVCDB;Initial Catalog=drap;Integrated Security=True");
{
SqlCommand new_doc_cmd = new SqlCommand("Insert Into docs(docTitle, docType, docContractType, docOrg, docDept, docDesc, PriorContCd, LegCompContId, docUpldDt, docUpldBy, docPath, venIdFk) Values(LTRIM(RTRIM(@docTitle)), LTRIM(RTRIM(@docType)), LTRIM(RTRIM(@docContractType)), LTRIM(RTRIM(@docOrg)), LTRIM(RTRIM(@docDept)), LTRIM(RTRIM(@docDesc)), LTRIM(RTRIM(@PriorContCd)), LTRIM(RTRIM(@LegCompContId)), LTRIM(RTRIM(@docUpldDt)), LTRIM(RTRIM(@docUpldBy)), LTRIM(RTRIM(@docPath)), LTRIM(RTRIM(@venIdFk)))", drap_cnxn);
new_doc_cmd.Parameters.AddWithValue("@docTitle", docTitleTextBox.Text);
new_doc_cmd.Parameters.AddWithValue("@docType", docTypeDdl.SelectedValue);
new_doc_cmd.Parameters.AddWithValue("@docContractType", docContractTypeDdl.SelectedValue);
new_doc_cmd.Parameters.AddWithValue("@docOrg", docOrgDdl.SelectedValue);
new_doc_cmd.Parameters.AddWithValue("@docDept", docDeptDdl.SelectedValue);
new_doc_cmd.Parameters.AddWithValue("@docDesc", docDescTextBox.Text);
new_doc_cmd.Parameters.AddWithValue("@PriorContCd", priorContCdTextBox.Text);
new_doc_cmd.Parameters.AddWithValue("@LegCompContId", legCompContIdTextBox.Text);
new_doc_cmd.Parameters.AddWithValue("@docUpldDt", DateTime.Now.ToString());
new_doc_cmd.Parameters.AddWithValue("@docUpldBy", System.Security.Principal.WindowsIdentity.GetCurrent().Name);
new_doc_cmd.Parameters.AddWithValue("@docPath", hdn_doc_path.Value);
new_doc_cmd.Parameters.AddWithValue("@venIdFk", hdn_ven_id.Value);
new_doc_cmd.Parameters.Add("@docIdPk", System.Data.SqlDbType.Int, 4).Direction = System.Data.ParameterDirection.Output;
drap_cnxn.Open();
new_doc_cmd.ExecuteNonQuery();
hdn_doc_id_2.Value = new_doc_cmd.Parameters["@docIdPk"].ToString();
drap_cnxn.Close();
if (IsPostBack)
{
docTitleTextBox.Text = "";
docTypeDdl.Text = "";
docContractTypeDdl.SelectedValue = "";
docOrgDdl.Text = "";
docDeptDdl.Text = "";
docDescTextBox.Text = "";
priorContCdTextBox.Text = "";
legCompContIdTextBox.Text = "";
hdn_doc_path.Value = "";
rg_vendors.DataBind();
//fv_ven_docs.DataBind();
}
else
{
ven_doc_upld_fail_lbl.Text = "Your document failed to upload. Please contact Compliance for assistance.";
}
}
}
}