-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathC#.cs
144 lines (119 loc) · 4.2 KB
/
C#.cs
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
=================================================================
@RESTFUL
Type name = (Type) Session["object"];
//How to add row into a table
//How to add trigger to db on events
//Look at Ch14CategoryMaint default.aspx
SqlDataSource1.InsertParameters["CategoryID"].DefaultValue = txtID.Text;
SqlDataSource1.Insert();
//Using dataset
DataSet ds = new DataSet("CutsomerDataSet");
SqlSataAdapter a = new Sql..
//get any restful services
public partial class ServerSide : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//configure web request object
string url = "http://localhost:53417/api/categories/";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.ContentType = "text/xml; encoding='utf-8'";
//send request, get xml response and convert to stream
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
//read stream in to a dataset
DataSet ds = new DataSet();
ds.ReadXml(stream);
//bind data set to gridview
grdCategories.DataSource = ds.Tables[0];
grdCategories.DataBind();
}
}
=================================================================
@INSERT
string au_id = TextBox1.Text;
string lname = TextBox2.Text;
string fname = TextBox3.Text;
string phone = TextBox4.Text;
string address = TextBox5.Text;
string city = TextBox6.Text;
string state = TextBox7.Text;
string zip = TextBox8.Text;
string contract = TextBox9.Text;
SqlDataSource1.InsertCommandType = SqlDataSourceCommandType.Text;
string query =
"INSERT INTO AUTHORS" +
"(" +
"AU_ID," +
"AU_LNAME," +
"AU_FNAME," +
"PHONE," +
"ADDRESS," +
"CITY," +
"STATE," +
"ZIP," +
"CONTRACT" +
") " +
"VALUES" +
"(" + "'" +
au_id + "'" + "," + "'" +
lname + "'" + "," + "'" +
fname + "'" + "," + "'" +
phone + "'" + "," + "'" +
address + "'" + "," + "'" +
city + "'" + "," + "'" +
state + "'" + "," + "'" +
zip + "'" + "," +
contract +
")";
SqlDataSource1.InsertCommand = query;
SqlDataSource1.Insert();
=================================================================
CategoryDB
private string GetConnectionString()
{
//return @"Data Source=(LocalDB)\v11.0;Integrated Security=True;AttachDbFilename=c:\inetpub\wwwroot\Halloween.mdf";
return @"user id=id;" +
"password=pw;server=server;" +
"database=Halloween; " +
"connection timeout=30";
//return ConfigurationManager
// .ConnectionStrings["Halloween"].ConnectionString;
}
=================================================================
STUDENT_ID
FIRSTNAME
LASTNAME
EMAIL PK
PHONE_NUMBER
GENDER
protected void Button1_Click(object sender, EventArgs e)
{
string STUDENT_ID = TextBox1.Text;
string FIRSTNAME = TextBox2.Text;
string LASTNAME = TextBox3.Text;
string EMAIL = TextBox4.Text;
string PHONE_NUMBER = TextBox5.Text;
//string GENDER = TextBox6.Text; //dropdown
SqlDataSource1.InsertCommandType = SqlDataSourceCommandType.Text;
string query =
"INSERT INTO STUDENTS" +
"(" +
"STUDENT_ID," +
"FIRSTNAME," +
"LASTNAME," +
"EMAIL," +
"PHONE_NUMBER," +
") " +
"VALUES" +
"(" + "'" +
STUDENT_ID + "'" + "," + "'" +
FIRSTNAME + "'" + "," + "'" +
LASTNAME + "'" + "," + "'" +
EMAIL + "'" + "," + "'" +
PHONE_NUMBER +
")";
SqlDataSource1.InsertCommand = query;
SqlDataSource1.Insert();
}