1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11 using System.Data.SqlClient;//
12
13 public partial class Basic_Write : System.Web.UI.Page
14 {
15 protected void Page_Load(object sender, EventArgs e)
16 {
17
18 }
19 protected void btnWrite_Click(object sender, EventArgs e)
20 {
21 //[1] 변수 선언부
22 string strName = txtName.Text;
23 string strEmail = txtEmail.Text;
24 string strHomepage = txtHomepage.Text;
25 string strTitle = txtTitle.Text;
26 string strContent = txtContent.Text;
27 string strPassword = txtPassword.Text;
28 string strEncoding = lstEncoding.SelectedValue;
29 string strPostIP = Request.UserHostAddress;//IP주소
30 string strSql = "WriteBasic";
31 #region 커넥션과 커멘드
32 //[2] 커넥션
33 SqlConnection objCon = new SqlConnection();
34 objCon.ConnectionString =
35 ConfigurationManager.ConnectionStrings[
36 "ConnectionString"].ConnectionString;//DB연결문자열지정
37 objCon.Open();
38 //[3] 커멘드
39 SqlCommand objCmd = new SqlCommand();
40 objCmd.Connection = objCon;
41 objCmd.CommandText = strSql;//
42 objCmd.CommandType = CommandType.StoredProcedure;//
43 #endregion
44 //[4] 파라미터 추가
45 objCmd.Parameters.AddWithValue("@Name", strName);
46 objCmd.Parameters.AddWithValue("@Email", strEmail);
47 objCmd.Parameters.AddWithValue("@Title", strTitle);
48 objCmd.Parameters.AddWithValue("@PostIP", strPostIP);
49 objCmd.Parameters.AddWithValue("@Content", strContent);
50 objCmd.Parameters.AddWithValue("@Password", strPassword);
51 objCmd.Parameters.AddWithValue("@Encoding", strEncoding);
52 objCmd.Parameters.AddWithValue("@Homepage", strHomepage);
53 //[5] 실행
54 objCmd.ExecuteNonQuery();
55 //[6] 마무리
56 objCon.Close(); Response.Redirect("List.aspx");
57 }
58 protected void btnList_Click(object sender, EventArgs e)
59 {
60 Response.Redirect("List.aspx");//리스트로 이동
61 }
62 }
63