Imports System.Data
Imports System.Data.SqlClient
Partial Class FormModifyFood
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack() Then
Dim ConnString = "Server=ANFIELD-AF3F1E7\SQLEXPRESS;Initial Catalog=ChildCare;Integrated Security=True"
Dim Conn = New SqlConnection(ConnString)
Conn.Open()
Dim SQLstr = "SELECT * FROM Food where Food_id='" & Request.QueryString("Food_id") & "'"
Dim com = New SqlCommand(SQLstr, Conn)
Dim da = New SqlDataAdapter(com)
Dim dt = New DataTable()
da.Fill(dt)
TextBox1.Text = dt.Rows(0)("Food_id")
TextBox2.Text = dt.Rows(0)("Food_name")
TextBox3.Text = dt.Rows(0)("Food_detail")
'FileUpload1.FileName = dt.Rows(0)("Food_pic") หนูเขียนโค๊ดแบบนี้มันเออเร่อค่ะ
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ConnString = "Server=ANFIELD-AF3F1E7\SQLEXPRESS;Initial Catalog=ChildCare;Integrated Security=True"
Dim Conn = New SqlConnection(ConnString)
Conn.Open()
Dim sqlstr = "update Food set Food_name='" & TextBox2.Text & "',Food_detail='" & TextBox3.Text & "',Food_pic='" & FileUpload1.FileName & "' where Food_id='" & Request.QueryString("Food_id") & "'"
Response.Write("บันทึกเรียบร้อยแล้ว<br>")
Response.Write("<a href=ModifyFood.aspx>กลับหน้าแก้ไขข้อมูลอาหาร</a>")
Dim com = New SqlCommand(sqlstr, Conn)
' com.ExecuteNonQuery()
'FileUpload1.SaveAs(Server.MapPath(FileUpload1.FileName)) คำสั่งตรงนี้ก็ลองใส่ๆดูแต่ใช้ไม่ได้ค่ะ
End Sub
End Class