-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate-consumer.aspx.cs
More file actions
81 lines (70 loc) · 2.83 KB
/
Create-consumer.aspx.cs
File metadata and controls
81 lines (70 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default7 : System.Web.UI.Page {
private string connectionString = WebConfigurationManager.ConnectionStrings["ChipDrop"].ConnectionString;
protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["FirstName"] = TextBox1.Text;
Session["LastName"] = TextBox2.Text;
Session["PhoneNumber"] = TextBox3.Text;
Session["Street"] = TextBox4.Text;
Session["City"] = TextBox5.Text;
Session["State"] = DropDownListState.Text;
Session["Zip"] = TextBox6.Text;
//Profile.FirstName = TextBox1.Text;
//Profile.PhoneNumber = TextBox2.Text;
//Profile.Address.Street = TextBox3.Text;
//Profile.Address.City = TextBox4.Text;
//Profile.Address.State = DropDownListState.Text;
//Profile.Address.Zip = TextBox6.Text;
if (TextBox1.Text == "" || TextBox2.Text == "" || TextBox3.Text == "" || TextBox4.Text == "" || TextBox5.Text == "" || DropDownListState.Text == "" || TextBox6.Text == "")
{
lblResults.Text = "Records require an ID, first name, and last name.";
return;
}
// Define ADO.NET objects
string insertSQL;
insertSQL = "INSERT INTO Customer(";
insertSQL += "first_name, last_name, phone, address, ";
insertSQL += "city, state, zip) ";
insertSQL += "VALUES (";
insertSQL += "@first_name, @last_name, @phone, @address, ";
insertSQL += "@city, @state, @zip)";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(insertSQL, con);
// Add the parameters.
cmd.Parameters.AddWithValue("@first_name", TextBox1.Text);
cmd.Parameters.AddWithValue("@last_name", TextBox2.Text);
cmd.Parameters.AddWithValue("@phone", TextBox3.Text);
cmd.Parameters.AddWithValue("@address", TextBox4.Text);
cmd.Parameters.AddWithValue("@city", TextBox5.Text);
cmd.Parameters.AddWithValue("@state", DropDownListState.Text);
cmd.Parameters.AddWithValue("@zip", TextBox6.Text);
// Try to open the database and execute the update.
int added = 0;
try
{
con.Open();
added = cmd.ExecuteNonQuery();
lblResults.Text = added.ToString() + " record Inserted.";
}
catch (Exception err)
{
lblResults.Text = "Error inserting record.";
lblResults.Text += err.Message;
}
finally
{
con.Close();
Response.Redirect("Default.aspx");
}
}
}