Private Sub MenuSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuSave.Click
Dim str As String
Dim stat As Boolean = False
Dim iDate As System.DateTime = Now
If RadioInternal.Checked Then
Typetrain = RadioInternal.Text
ElseIf RadioExternal.Checked Then
Typetrain = RadioExternal.Text
Else
Typetrain = ""
End If
str = "insert into tbcoursetrain(Cou_id,Cou_Name,Cou_Generate,Cou_StDate,Cou_EndDate,Cou_Cost,Cou_Hours,Cou_Location,Cou_TypeTrain)"
str += " Values (NULL,?,?,?,?,?,?,?,?)"
Dim cmd = CreatCmdBKI(str)
cmd.Parameters.AddWithValue("?", CStr(TextCourseName.Text))
cmd.Parameters.AddWithValue("?", CInt(TextGenerate.Text))
cmd.Parameters.AddWithValue("?", CDate(dtpStDate.Value.ToString("yyyy/MM/dd", DF)))
cmd.Parameters.AddWithValue("?", CDate(dtpEndDate.Value.ToString("yyyy/MM/dd", DF)))
cmd.Parameters.AddWithValue("?", CDbl(TextCost.Text))
cmd.Parameters.AddWithValue("?", CInt(TextHours.Text))
cmd.Parameters.AddWithValue("?", CStr(TextLocation.Text))
cmd.Parameters.AddWithValue("?", CStr(Typetrain))
cmdExcBKI(cmd, strPayrollCustom)
'Dim result As Integer = cmd.ExecuteNonQuery()
'If result = -1 Then
' MsgBox("เพิ่มข้อมูลหลักสูตรการฝึกอบรมไม่สำเร็จ" & "แจ้งเตือนการทำงาน", MsgBoxStyle.Critical, "Insert")
' Exit Sub
'Else
' MsgBox("เพิ่มข้อมูลหลักสูตรการฝึกอบรมเรียบร้อยแล้ว" & "แจ้งเตือนการทำงาน", MsgBoxStyle.Information, "Insert")
'End If
'--Call calltrainvalue()
End Sub
Tag : .NET, MySQL, VB.NET, VS 2010 (.NET 4.x), Windows
ได้แล้วครับพี่ผมถามอีกนิดหนึงได้ไหมครับว่า ทำไมข้อมูลใน Datagridview ไม่ Show ครับ พอดีผมมือใหม่ VB เรียนมาก็ไม่ได้นำไปใช้ต่อเลยลืมครับ ขอความช่วยเหลือหน่อยครับ
Code (VB.NET)
Private Sub grdCourseTrand_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grdCourseTrand.CellContentClick
Call calltrainvalue()
End Sub
Private Sub calltrainvalue()
Dim str As String
Dim Cname As String
Dim generate As Integer
Dim datestart As Date
Dim dateEnd As Date
Dim CostTrn As Double
Dim Hours As Integer
Dim Location As String
Dim TrainType As String
For r = 0 To grdCourseTrand.Rows.Count - 1
str = "select * from tbcoursetrain "
Dim cmd = CreatCmdBKI(str)
dt = GetDataTableBKI(cmd, strPayrollCustom)
If dt.Rows.Count > 0 Then
Cname = CStr(dt.Rows(0).Item("Cou_Name").ToString)
generate = CInt(dt.Rows(0).Item("Cou_Generate").ToString)
datestart = CDate(dt.Rows(0).Item("Cou_StDate").ToString)
dateEnd = CDate(dt.Rows(0).Item("Cou_EndDate").ToString)
CostTrn = CDbl(dt.Rows(0).Item("Cou_Cost").ToString)
Hours = CInt(dt.Rows(0).Item("Cou_Hours").ToString)
Location = CStr(dt.Rows(0).Item("Cou_Location").ToString)
TrainType = CStr(dt.Rows(0).Item("Cou_TypeTrain").ToString)
grdCourseTrand.Item("Course_Name", r).Value = CStr("Cname")
grdCourseTrand.Item("Generation", r).Value = CInt(generate)
grdCourseTrand.Item("startdate", r).Value = CDate(datestart)
grdCourseTrand.Item("enddate", r).Value = CDate(dateEnd)
grdCourseTrand.Item("Cost", r).Value = CDbl(CostTrn)
grdCourseTrand.Item("Nums_Hours", r).Value = CInt(Hours)
grdCourseTrand.Item("Location", r).Value = CStr("Location")
grdCourseTrand.Item("Type", r).Value = CStr("TrainType")
End If
Next
End Sub