-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnewsDetail.aspx.cs
More file actions
44 lines (42 loc) · 1.29 KB
/
newsDetail.aspx.cs
File metadata and controls
44 lines (42 loc) · 1.29 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
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class newsDetail : System.Web.UI.Page
{
string strCon = ConfigurationManager.ConnectionStrings["DatabaseConnection"].ConnectionString;
SqlConnection conn;
SqlCommand comm;
protected void Page_Load(object sender, EventArgs e)
{
int id =Convert.ToInt32(Request.QueryString["id"]);
string sql = String.Format("select * from gd_news where id='{0}'", id);
using (conn = new SqlConnection(strCon))
{
conn.Open();
comm = new SqlCommand(sql, conn);
SqlDataReader reader = comm.ExecuteReader();
try
{
if (reader.Read())
{
Title.Text = reader.GetString(1);
Content.Text = reader.GetString(2);
Time.Text = string.Format(reader.GetDateTime(3).ToString());
}
}
catch (System.Data.SqlTypes.SqlNullValueException ex)
{
Response.Write(ex.Message);
}
finally
{
}
reader.Close();
}
}
}