Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration
Imports System.Web.UI.WebControls
Partial Public Class HR_1
Inherits System.Web.UI.Page
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim strConn As String
Dim strSql As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strTest1 As String = Request.QueryString("abc")
Response.Write(strTest1)
strConn = WebConfigurationManager.ConnectionStrings("connects").ConnectionString
conn = New SqlConnection(strConn)
conn.Open()
btnDelete.Attributes.Add("onClick", "javascript:return confirm('Are you sure you want to delete to delete these rows?')")
If Not Page.IsPostBack() Then
DataBind()
End If
Dim strSql As String
strSql = "SELECT employee.employee_id, employee.username, employee.password, employee.first_name, employee.last_name, employee.email, department.depertment_name, roces_role.access_level_name, employee_authentication.authentication_name, employee_head.employee_head_name, center.center_name_middle FROM employee INNER JOIN employee_authentication ON employee.authentication_id = employee_authentication.authentication_id INNER JOIN employee_head ON employee.employee_head_id = employee_head.employee_head_id INNER JOIN roces_role ON employee.access_level_id = roces_role.access_level_id INNER JOIN department ON employee.department_id = department.department_id INNER JOIN center ON department.center_id = center.center_id"
Dim da As New SqlDataAdapter(strSql, conn)
Dim ds As New DataSet
da.Fill(ds, "employee")
gvEmployee.DataSource = ds.Tables("employee")
gvEmployee.DataBind()
End Sub
Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnDelete.Click
Dim chkbox As CheckBox = New CheckBox
For Each grdRow As GridViewRow In gvEmployee.Rows
chkbox = CType(grdRow.FindControl("chkItem"), CheckBox)
If chkbox.Checked Then
Dim employee_id As String = gvEmployee.DataKeys(grdRow.RowIndex).Value.ToString
Dim department_name As String = gvEmployee.DataKeys(grdRow.RowIndex).Value.ToString
Dim center_name As String = gvEmployee.DataKeys(grdRow.RowIndex).Value.ToString
Dim authentication_name As String = gvEmployee.DataKeys(grdRow.RowIndex).Value.ToString
Dim employee_head_name As String = gvEmployee.DataKeys(grdRow.RowIndex).Value.ToString
Dim access_level_name As String = gvEmployee.DataKeys(grdRow.RowIndex).Value.ToString
SDSEmployee.DeleteParameters("employee_id").DefaultValue = employee_id
SDSEmployee.DeleteParameters("department_name").DefaultValue = department_name
SDSEmployee.DeleteParameters("center_name").DefaultValue = center_name
SDSEmployee.DeleteParameters("authentication_name").DefaultValue = authentication_name
SDSEmployee.DeleteParameters("employee_head_name").DefaultValue = employee_head_name
SDSEmployee.DeleteParameters("access_level_name").DefaultValue = access_level_name
SDSEmployee.Delete()
End If
Next
gvEmployee.DataBind()
End Sub
End Class
รบกวนช่วยทีนะคะ
Tag : ASP.NET, Ms SQL Server 2005, Web (ASP.NET), WebService, VS 2008 (.NET 3.x)