-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContactUs.aspx.cs
64 lines (52 loc) · 2.11 KB
/
ContactUs.aspx.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
using System;
using System.Web.UI;
using System.Data;
using System.Data.SqlClient;
using System.Xml.Linq;
using System.Drawing;
using System.Web.UI.WebControls;
using System.Web.Services.Description;
namespace Lab3.MasterPages
{
public partial class ContactUs : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void submitForm_Click(object sender, EventArgs e)
{
string ID = id.Text;
string Name = name.Text;
string Email = email.Text;
string Comment = comment.Text;
SqlConnection con = new SqlConnection
("Data Source = LAPTOP-BM8BRT21\\SQLEXPRESS; Initial Catalog = TestDatabase; Integrated Security = True; Pooling = False");
SqlCommand com = new SqlCommand();
try
{
con.Open();
com.Connection = con;
//Response.Write("Successful\n");
SqlDataAdapter cmd = new SqlDataAdapter();// Create a object of SqlDataAdapter class
cmd.InsertCommand = new SqlCommand("INSERT INTO contactus VALUES (@id, @name, @email, @comment) ", con); //Pass the connection object to cmd
cmd.InsertCommand.Parameters.Add("@id", SqlDbType.VarChar).Value = ID;
cmd.InsertCommand.Parameters.Add("@name", SqlDbType.Text).Value = Name;
cmd.InsertCommand.Parameters.Add("@email", SqlDbType.Text).Value = Email;
cmd.InsertCommand.Parameters.Add("@comment", SqlDbType.Text).Value = Comment;
cmd.InsertCommand.ExecuteNonQuery(); //to execute the SQL command
}
catch (Exception ex)
{
Response.Write("Error: " + ex.ToString());
}
finally
{
con.Close();
id.Text = string.Empty;
name.Text = string.Empty;
email.Text = string.Empty;
comment.Text = string.Empty;
}
}
}
}