/
merchandise.aspx.cs
56 lines (49 loc) · 1.61 KB
/
merchandise.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
using System;
using System.Configuration;
using System.Data;
using System.Web.UI;
using Npgsql;
namespace FooBlog
{
public partial class merchandise : Page
{
protected void Page_Load(object sender, EventArgs e)
{
Load_Form();
}
protected void Load_Form()
{
try
{
using (var conn = new NpgsqlConnection())
{
conn.ConnectionString =
ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString;
conn.Open();
var cmd =
new NpgsqlCommand(
"SELECT merchid, merchname, merchprice, merchbrief FROM merchandise WHERE merchenabled= true ORDER BY merchname",
conn);
var da = new NpgsqlDataAdapter(cmd);
var ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count == 0)
{
errorLabel.Text = "There are no items.";
}
else
{
merchList.DataSource = ds;
merchList.DataBind();
errorLabel.Text = "";
}
}
}
catch (Exception ex)
{
FooLogging.WriteLog(ex.ToString());
errorLabel.Text = "Something has gone wrong. A log has been forwarded to the site administrator.";
}
}
}
}