Finishing up some homework and Im having trouble with figuring out how to take information generated in sql column(a primary key set up to assign a record number to a customer example 1046) at submit and writing it to my redirected recipt page. I call it recipt.aspx. Any takers
Professor says to use a datareader...but things go bad after that.
public partial class _Default : System.Web.UI.Page
{
String cnStr = "EDITED FOR THE PURPOSE OF NOT DISPLAYED SQL SERVERta Source=111.11.111.11; uid=xxxxxxx; password=xxxx; database=xxxxxx; ";
String insertStr;
SqlDataReader reader;
SqlConnection myConnection = new SqlConnection();
protected void submitbutton_Click(object sender, EventArgs e)
{
myConnection.ConnectionString = cnStr;
try
{
//more magic happens as myConnection opens
myConnection.Open();
insertStr = "insert into connectAssignment values ('" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + bigtextthing.Text + "','" + DropDownList1.SelectedItem.Value + "')";
//magic happens as Connection string is assigned to connection object and passes in the SQL statment
//associate the command to the the myConnection connection object
SqlCommand cmd = new SqlCommand(insertStr, myConnection);
cmd.ExecuteNonQuery();
Session["passmyvalue1"] = TextBox2.Text;
Session["passmyvalue2"] = TextBox3.Text;
Session["passmyvalue3"] = TextBox4.Text;
Session["passmyvalue4"] = TextBox5.Text;
Session["passmyvalue5"] = bigtextthing.Text;
Session["I NEED SOME HELP RIGHT HERE"] =Textbox6.Text;
Response.Redirect("receipt.aspx");
}
catch
{
bigtextthing.Text =
"Error submitting" + "Possible casues: Internet is down,server is down, check your settings!";
}
finally
{
myConnection.Close();
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
bigtextthing.Text = "";
}
//reset validators?
}
The recipt page
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(Session["passmyvalue1"] != null)
{
TextBox1.Text = (string)Session["passmyvalue1"];
TextBox2.Text = (string)Session["passmyvalue2"];
TextBox3.Text = (string)Session["passmyvalue3"];
TextBox4.Text = (string)Session["passmyvalue4"];
TextBox5.Text = (string)Session["passmyvalue5"];
TextBox6.Text = I don't know ;
}
}
}
THanks for the help