Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

C#
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)
    {

    }
    
   }
Posted
Comments
Tom Marvolo Riddle 29-Oct-13 9:13am    
show it in Gridview
Computer Wiz99 29-Oct-13 9:17am    
How? The form will still have textboxes on it. I was thinking on just auto populate the textboxes from the database. Is that a better way of doing it also? I already have some textboxes that are auto populated to show last year numbers.
samit kaneriya 29-Oct-13 9:28am    
Add if (!IsPostBack) in page_load
Computer Wiz99 29-Oct-13 9:30am    
Ok, Thanks. Can you look at my other questions?
Tom Marvolo Riddle 29-Oct-13 9:33am    
I have to log off now.Sorry

1 solution

Quote:
The form will still have textboxes on it

No problem.Refer this link.it might be helpgul:
how-to-inserteditupdate-and-delete-data[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900