Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
GridViewGTData()
End Sub
Private Sub GridViewGTData()
If IsNothing(Session("GeneralTestTable")) Then
dt = New DataTable()
dt.Columns.Add(New DataColumn("Clean", GetType(String)))
dt.Columns.Add(New DataColumn("Infect", GetType(String)))
dt.Columns.Add(New DataColumn("Printing", GetType(String)))
dt.Columns.Add(New DataColumn("GTAVG", GetType(String)))
dt.Columns.Add(New DataColumn("GTNote", GetType(String)))
Session("GeneralTestTable") = dt
End If
dt = DirectCast(Session("GeneralTestTable"), DataTable)
gvRMRT_GT.DataSource = dt
gvRMRT_GT.DataBind()
End Sub
Private Sub AddToTableGT()
dr = dt.NewRow
dr("Clean") = rdbClean.SelectedItem.ToString()
dr("Infect") = rdbInfect.SelectedItem.ToString()
dr("Printing") = rdbPrinting.SelectedItem.ToString()
If rdbClean.SelectedItem.Value <> "0" And rdbInfect.SelectedItem.Value <> "0" And rdbPrinting.SelectedItem.Value <> "0" Then
dr("GTAVG") = "ผ่าน"
Else
dr("GTAVG") = "ไม่ผ่าน"
End If
dr("GTNote") = txtRMRT_GT_Note.Text.Trim
dt.Rows.Add(dr)
Session("GeneralTestTable") = dt
GridViewGTData()
End Sub
Protected Sub btnRMRT_GT_Add_Click(sender As Object, e As EventArgs) Handles btnRMRT_GT_Add.Click
AddToTableGT()
End Sub
Private Sub AddToDB()
ConnectDB()
GridViewGTData()
strSQL = "INSERT INTO GeneralTest (GT_CLEAN,GT_INFECT,GT_PRINTING,GT_NOTE) VALUES ('" & dt.Rows(i) ("Clean") & "','" & dt.Rows(i)("Infect") & "','" & dt.Rows(i)("Printing") & "','" & dt.Rows(i)("GTNote") & "')"
objCmd = New SqlCommand(strSQL, objConn)
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
Next
objConn.Close()
MsgBox("บันทึกข้อมูลสำเร็จ")
End Sub
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), VB.NET, VS 2012 (.NET 4.x)