-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateProducts.aspx.cs
58 lines (55 loc) · 2.12 KB
/
UpdateProducts.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
namespace Project_Stuff
{
public partial class UpdateProducts : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PSConnectionStrings"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
SqlCommand objCmd = new SqlCommand();
objCmd.Connection = con;
objCmd.CommandText = "SELECT * FROM menuItems WHERE itemID =" + Request.QueryString["ID"];
objCmd.CommandType = CommandType.Text;
SqlDataReader sdr = null;
con.Open();
sdr = objCmd.ExecuteReader();
while (sdr.Read())
{
TextBoxName.Text = (sdr["itemName"].ToString());
TextBoxPrice.Text = (sdr["itemPrice"].ToString());
Image.ImageUrl = (sdr["itemImage"]).ToString();
TextBoxBio.Text = (sdr["itemDescription"].ToString());
}
con.Close();
}
protected void ButtonUpdate_Click(object sender, EventArgs e)
{
if (UploadProductImage.HasFile)
{
string imagePath = "~/images/" + UploadProductImage.FileName;
UploadProductImage.SaveAs(Server.MapPath(imagePath).ToString());
SqlCommand cmd = new SqlCommand("UPDATE menuItems SET itemName = '" + TextBoxName.Text + "', itemPrice ='" + TextBoxPrice.Text + "', itemImage = '" + imagePath + "', itemDescription = '" + TextBoxBio.Text + "' WHERE itemID = " + Request.QueryString["ID"], con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
BindData();
}
}
}
}