นี้คือโค้ด นะ ครับ
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblMsg.Text = ""
lblCpath.Text = ""
btnDel.Attributes.Add("onclick", "if(confirm('คุณต้องการที่จะลบข้อมูลนี้ใช่หรือไม่')==false){return false;}")
If Not Page.IsPostBack Then
Dim hid As Integer = 0
hid = Request.QueryString("hid")
ViewState("hid") = hid
Dim str As String = ""
Dim Cnn As New DBConnection("DBMASTER")
Dim cmd As DBCommand
Dim dsHouse As New DataSet
Try
Cnn.OpenConnection()
If hid <> 0 Then
btnDel.Visible = True
str = "SELECT [HOUSE_ID],[SUP_ID],[HNAME],TYPE_ID,"
str &= " dbo.getTypeName(TYPE_ID)AS TYPENAME,[HADDRESS],[PROVINCE_ID],"
str &= " dbo.getProvince([PROVINCE_ID])AS PROVINCENAME"
str &= ",[PRICE],[PICTURE_PATH],[AREA],[DESCRIPTION],[CREATEDATE],[STATUS]"
str &= " FROM [tbHOUSE]"
str &= " WHERE HOUSE_ID = " & hid
cmd = New DBCommand(Cnn, str, CommandType.Text)
cmd.Fill(dsHouse)
If dsHouse.Tables(0).Rows.Count > 0 Then
TextBox1.Text = dsHouse.Tables(0).Rows(0).Item("HNAME").ToString.Trim
dd1.SelectedValue = dsHouse.Tables(0).Rows(0).Item("TYPE_ID").ToString.Trim
dd2.SelectedValue = dsHouse.Tables(0).Rows(0).Item("PROVINCE_ID").ToString.Trim
lblCpath.Text = "file ปัจจุบัน : " & dsHouse.Tables(0).Rows(0).Item("PICTURE_PATH").ToString.Trim
TextBox3.Text = dsHouse.Tables(0).Rows(0).Item("HADDRESS").ToString.Trim
TextBox4.Text = dsHouse.Tables(0).Rows(0).Item("PRICE").ToString.Trim
TextBox5.Text = dsHouse.Tables(0).Rows(0).Item("AREA").ToString.Trim
TextBox6.Text = dsHouse.Tables(0).Rows(0).Item("DESCRIPTION").ToString.Trim
End If
Else
btnDel.Visible = False
End If
Catch ex As Exception
Finally
Cnn.CloseConnection()
End Try
End If
End Sub
Protected Sub btnDel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDel.Click
Dim hid As Integer = 0
Dim str As String = ""
Dim Cnn As New DBConnection("DBMASTER")
Dim cmd As DBCommand
Try
Cnn.OpenConnection()
If ViewState("hid") <> 0 Then
btnDel.Visible = True
str = "delete tbHOUSE"
str &= " WHERE HOUSE_ID = " & hid
cmd = New DBCommand(Cnn, str, CommandType.Text)
cmd.ExecuteNonQuery()
lblMsg.Text = "ลบข้อมูลเรียบร้อย"
Response.Redirect("frmsupmain.aspx")
End If