Imports System.Data
Imports System.IO
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page
Private Property BinaryReader As StreamReader
Public ObjDb As New Datacenter.Data.clsDBSQLBased(ConfigurationManager.ConnectionStrings("ConStr").ToString)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
bindposi()
binddepartments()
'BindData()
Me.btnSave.Visible = True
Me.btnCancel.Visible = True
End If
End Sub
Protected Sub bindposi()
Dim sql As String
Dim dv As DataView
sql = " SELECT posi_id,posi_name FROM [tb_position]"
sql += " ORDER BY posi_id "
dv = ObjDb.GetDataSet(sql).Tables(0).DefaultView
If dv.Count > 0 Then
Me.ddlposi.DataSource = dv
Me.ddlposi.DataBind()
Me.ddlposi.Items.Insert(0, "== กรุณาเลือก ==")
End If
End Sub
Protected Sub binddepartments()
Dim sql As String
Dim dv As DataView
sql = " SELECT dept_id,dept_name FROM [tb_departments]"
sql += " ORDER BY dept_id "
dv = ObjDb.GetDataSet(sql).Tables(0).DefaultView
If dv.Count > 0 Then
Me.ddldept.DataSource = dv
Me.ddldept.DataBind()
Me.ddldept.Items.Insert(0, "== กรุณาเลือก ==")
End If
End Sub
Protected Sub SaveData()
Dim sql As String
sql = "INSERT INTO tb_staff(staff_id,staff_name,email,addr,tel_staff,pois_id,dept_id)"
sql += " VALUES ('" & Trim(Me.txtstaff_id.Text) & "','" & Trim(Me.txtstaff_name.Text) & "', "
sql += " '" & Trim(Me.txtemail.Text) & "','" & Trim(Me.txtaddr.Text) & "','" & Trim(Me.txttel_sff.Text) & "','" & Trim(Me.ddlposi.SelectedValue) & "','" & Trim(Me.ddldept.SelectedValue) & "') "
Response.Write(sql)
ObjDb.ExecuteNonQuery(sql)
Page.ClientScript.RegisterStartupScript(Page.GetType(), "clientScript", "alert('บันทึกข้อมูลเรียบร้อย');", True)
End Sub
Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.txtstaff_id.Text = ""
Me.txtstaff_name.Text = ""
Me.txtemail.Text = ""
Me.txtaddr.Text = ""
Me.txttel_sff.Text = ""
End Sub
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
SaveData()
End Sub
Protected Sub UpdateData()
Dim sql As String
sql = " Update tb_staff SET staff_id='" & Trim(Me.txtstaff_id.Text) & "',staff_name='" & Trim(Me.txtstaff_name.Text) & "',email='" & Trim(Me.txtemail.Text) & "', "
sql += " addr='" & Trim(Me.txtaddr.Text) & "',tel_staff='" & Trim(Me.txttel_sff.Text) & "' "
sql += " pois_id='" & Trim(Me.ddlposi.SelectedValue) & "',dept_id='" & Trim(Me.ddldept.SelectedValue) & "' "
sql += " WHERE staff_id ='" & Request.QueryString("staff_id") & "' " 'ส่วนการส่งid มันก็ ไม่ส่งให้ ต้องทำยังไงคะ ช่วยแนะนำ หน่อนนะคะ
'
'
Response.Write(sql)
ObjDb.ExecuteNonQuery(sql)
Page.ClientScript.RegisterStartupScript(Page.GetType(), "clientScript", "alert('แก้ไขข้อมูลเรียบร้อย');", True)
End Sub
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
UpdateData()
End Sub
End Class