本文介绍了提交后将数据保存在表单中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表单,用户可以将数据输入到文本框中。当用户单击提交并将数据保存到数据库中时。我希望用户能够返回到表单并查看他们刚刚输入的数据。这是怎么做的?
I have a form that a user can enter data into textboxes. When the user clicks on submit and the data is saved into the database. I would like the user to be able to go back to the form and see the data they just entered. How is this done?
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing.Printing;
using System.Web.SessionState;
public partial class FinancialProfileFormD : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ButtonPrint.Attributes.Add("onclick", "window.print(); return false");
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
con.Open();
SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
con2.Open();
TextBoxINST_ID.Text = Session["inst_id"].ToString();
SqlCommand scmd = new SqlCommand("Select INST_ID, LongName, City, State from TableCOCINST where INST_ID = '" + TextBoxINST_ID.Text + "'", con);
SqlCommand scmd2 = new SqlCommand("Select INST_ID, INSTRUCTIO, RESEARCH, ACADEMIC_S, NET_AID, AUXILIARY_, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT from TableFIN2012 where INST_ID = '" + TextBoxINST_ID.Text + "'", con2);
SqlDataReader dr = scmd.ExecuteReader();
SqlDataReader dr2 = scmd2.ExecuteReader();
if (dr.Read())
if (dr2.Read())
{
lblSchool2.Text = dr["LongName"].ToString();
lblSchool.Text = dr["LongName"].ToString();
lblCity.Text = dr["City"].ToString();
lblState.Text = dr["State"].ToString();
TextBoxLYInstr.Text = dr2["INSTRUCTIO"].ToString();
TextBoxLYResPs.Text = dr2["RESEARCH"].ToString();
TextBoxLYAcadSSSIS.Text = dr2["ACADEMIC_S"].ToString();
TextBoxLYAuxE.Text = dr2["AUXILIARY_"].ToString();
TextBoxLYNGAS.Text = dr2["NET_AID"].ToString();
TextBoxLYAOE.Text = dr2["OTHEREXP"].ToString();
TextBoxLYTA.Text = dr2["TOTASSETS"].ToString();
TextBoxLYTL.Text = dr2["TOTLIABILITY"].ToString();
TextBoxLYNPRNA.Text = dr2["NoNEXPPERMRESASSETS"].ToString();
TextBoxLYTUNA.Text = dr2["UNRNETASSETS"].ToString();
TextBoxLYTR.Text = dr2["TOTALREV"].ToString();
TextBoxLYTFN.Text = dr2["TUITFEES"].ToString();
TextBoxLYCD.Text = dr2["CURRDEBT"].ToString();
TextBoxLYLTD.Text = dr2["LONGTERMDEBT"].ToString();
}
dr.Close();
con.Close();
dr2.Close();
con2.Close();
}
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand ("Insert into TableFIN2013 (INST_ID, TOTAL_REVE, INSTRUCTIO, RESEARCH, ACADEMIC_S, NET_AID, AUXILIARY_, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LOMGTERMDEBT) values (@INST_ID, @TOTAL_REVE, @INSTRUCTIO, @RESEARCH, @ACADEMIC_S, @NET_AID, @AUXILIARY_, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LOMGTERMDEBT)", con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID);
cmd.Parameters.AddWithValue("@TOTAL_REVE", TextBoxTR);
cmd.Parameters.AddWithValue("@INSTRUCTIO", TextBoxInstr.Text);
cmd.Parameters.AddWithValue("@RESEARCH", TextBoxResPs.Text);
cmd.Parameters.AddWithValue("@ACADEMIC_S", TextBoxAcadSSSIS.Text);
cmd.Parameters.AddWithValue("@NET_AID", TextBoxNGAS.Text);
cmd.Parameters.AddWithValue("@AUXILIARY_", TextBoxAuxE.Text);
cmd.Parameters.AddWithValue("@OTHEREXP", TextBoxAOE.Text);
cmd.Parameters.AddWithValue("@TOTASSETS", TextBoxTA.Text);
cmd.Parameters.AddWithValue("@TOTLIABILITY", TextBoxTL.Text);
cmd.Parameters.AddWithValue("@NoNEXPPERMRESASSETS", TextBoxNPRNA.Text);
cmd.Parameters.AddWithValue("@EXPENDABLE", TextBoxETRNA.Text);
cmd.Parameters.AddWithValue("@UNRNETASSETS", TextBoxTUNA.Text);
cmd.Parameters.AddWithValue("@TOTALREV", TextBoxTR.Text);
cmd.Parameters.AddWithValue("@TUITFEES", TextBoxTFN.Text);
cmd.Parameters.AddWithValue("@CURRDEBT", TextBoxCD.Text);
cmd.Parameters.AddWithValue("@LOMGTERMDEBT", TextBoxLTD.Text);
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("FinancialProfileFormD.aspx");
}
protected void ButtonPrint_Click(object sender, EventArgs e)
{
}
}
推荐答案
Quote:
表单上仍然有文本框
没问题。请看这个链接。可能是helpgul:
[]
这篇关于提交后将数据保存在表单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!