Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Partial Class editNews
Inherits System.Web.UI.Page
Dim conn As New SqlConnection
Dim ds As New DataSet
Dim dt As DataRow
Dim newid As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strConn As String
strConn = "Data Source=192.168.1.95;Initial Catalog=PublicReportDB;user id=sa;password = p@ssw0rd;"
With conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
newid = Request.QueryString("newid")
Dim SelectCommand As String = "SELECT * FROM news WHERE newid = '" & newid & "' "
Dim da As New SqlDataAdapter(SelectCommand, conn)
da.Fill(ds, "select")
dt = ds.Tables("select").Rows(0)
lbldate.Text = dt("date")
txtTitle.Text = dt("title")
txtDetail.Text = dt("detail")
imgEdit.ImageUrl = "upload/" & dt("fileupload")
End Sub
Protected Sub btnCon_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCon.Click
Dim UpdateCommand As String
UpdateCommand = " UPDATE news " & _
" SET title ='" & txtTitle.Text & "'," & _
" detail ='" & txtDetail.Text & "'," & _
" fileupload ='" & FileUpload1.FileName & "'" & _
" WHERE newid =" & newid & ""
Dim com As New SqlCommand(UpdateCommand, conn)
With com
.Connection = conn
.CommandType = CommandType.Text
.CommandText = UpdateCommand
.ExecuteNonQuery()
End With
End Sub
Protected Sub btnCancle_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancle.Click
Response.Redirect("viewAddnews.aspx")
End Sub
End Class
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strConn As String
strConn = "Data Source=192.168.1.95;Initial Catalog=PublicReportDB;user id=sa;password = p@ssw0rd;"
With conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
newid = Request.QueryString("newid")
IF NOT Page.IsPostBack() Then
Dim SelectCommand As String = "SELECT * FROM news WHERE newid = '" & newid & "' "
Dim da As New SqlDataAdapter(SelectCommand, conn)
da.Fill(ds, "select")
dt = ds.Tables("select").Rows(0)
lbldate.Text = dt("date")
txtTitle.Text = dt("title")
txtDetail.Text = dt("detail")
imgEdit.ImageUrl = "upload/" & dt("fileupload")
End IF
End Sub
ใส่
IF NOT Page.IsPostBack() Then
End IF
PostBack คือ การ submit ค่าในรูปแบบ Event ของ Action Form