Private Sub BNAdd_Click(sender As Object, e As EventArgs) Handles BNAdd.Click
If CBITPlanndList.Text = "" Or CT.Text = "" Or CBItemNo.Text = "" Or txtDate.Text = "" Or txtQty.Text = "" Or CBModel.Text = "" Or CBStaff.Text = "" Or txtRemark.Text = "" Or txtOrderedTimes.Text = "" Or txtTransContractorID.Text = "" Then
MessageBox.Show("กรุณาใส่ข้อมูล")
Else
Dim str = txtDate.Text
Dim strArr() As String
strArr = str.Split(CChar(" "))
Dim TimeDate As String = strArr(0)
Dim Result As MsgBoxResult
Result = CType(MessageBox.Show("คุณต้องการบันทึกข้อมูลใช่หรือไม่", "คำเตือน", MessageBoxButtons.YesNo), MsgBoxResult)
If Result = MsgBoxResult.Yes Then
' MessageBox.Show(txtCVNo.Text)
Dim cmd As OleDbCommand = Nothing
sql_search = " SELECT TOP 1 * from IT_TransContractor"
Dim sqlwhere As String = " where (IT_TransContractor.PlannedListID LIKE '" & CBITPlanndList.Text & "') and (IT_TransContractor.ContractorID LIKE '" & CT.Text & "') and(IT_TransContractor.ItemNo LIKE '" & CBItemNo.Text & "')order by OrderedTimes desc"
sqlemp = sql_search & sqlwhere
da2 = New OleDbDataAdapter(sqlemp, conn)
da2.Fill(ds2, "IT_PlannedList")
dt2 = ds2.Tables("IT_PlannedList")
' MessageBox.Show(66)
txtOrderedTimes.DataBindings.Add(New Binding("text", dt2, "OrderedTimes"))
Dim txtOrderedTimes2 As String = txtOrderedTimes.Text + 1
sql_search2 = " SELECT TOP 1 * from IT_TransContractor"
Dim sqlwhere2 As String = " order by TransContractorID desc"
sqlemp2 = sql_search2 & sqlwhere2
' MessageBox.Show(sqlemp2)
da3 = New OleDbDataAdapter(sqlemp2, conn)
da3.Fill(ds3, "IT_TransContractor")
dt3 = ds3.Tables("IT_TransContractor")
' MessageBox.Show(77)
txtTransContractorID.DataBindings.Add(New Binding("text", dt3, "TransContractorID"))
Dim txtTransContractorID2 As Integer = txtTransContractorID.Text + 1
MessageBox.Show(txtDate.Text)
Dim NumMonthS As String = condata.CheckData(txtDate.Text)
Dim T = txtDate.Text
Dim TArr() As String
TArr = T.Split(CChar("/"))
Dim txt3 As Integer = strArr(2) - 543
MessageBox.Show(txt3)
Dim txt1 As String = strArr(0) & "/" & NumMonthS & "/" & txt3
' Dim txt1 As String = strArr(0) & "/" & NumMonthS & "/" & strArr(2)
MessageBox.Show(txt1)
condata.addITEquipmentAwaiting(PlannedListID:=CBITPlanndList.Text, ContractorID:=CT.Text, ItemNo:=CBItemNo.Text, ReceivedDate:=txt1, ReceivedQty:=txtQty.Text, ModelID:=model.Text, ApprovedStaffPosition:=CBStaff.Text, Remark:=txtRemark.Text, OrderedTimes:=txtOrderedTimes2, TransContractorID:=txtTransContractorID2)
MessageBox.Show("ข้อมูลถูกบันทึกเรียบร้อย")
'MessageBox.Show(TextBox1.Text)
ElseIf Result = MsgBoxResult.No Then
MessageBox.Show("การบันทึก ถูกยกเลิก")
End If
End If
End Sub
ฟังชั่น addITEquipmentAwaiting
Public Sub addITEquipmentAwaiting(ByVal PlannedListID As Integer, ByVal ContractorID As Integer, ByVal ItemNo As String, ByVal ReceivedDate As String, ByVal ReceivedQty As Integer, ByVal ModelID As Integer, ByVal ApprovedStaffPosition As Integer, ByVal Remark As String, ByVal OrderedTimes As Integer, ByVal TransContractorID As Integer)
Dim dt As DataTable
Dim dr As DataRow
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Connect()
Dim sqlAgencies As String
sqlAgencies = "Select * From IT_TransContractor"
da = New OleDbDataAdapter(sqlAgencies, conn)
da.Fill(ds, "IT_TransContractor")
dt = ds.Tables("IT_TransContractor")
dr = dt.NewRow() '<-------- เพิ่มแถมใหม่ในObj dt
dr("TransContractorID") = TransContractorID
dr("PlannedListID") = PlannedListID
dr("ContractorID") = ContractorID
dr("ItemNo") = ItemNo
dr("ReceivedDate") = ReceivedDate
dr("ReceivedQty") = ReceivedQty
dr("ModelID") = ModelID
dr("ApprovedStaffPosition") = ApprovedStaffPosition
dr("Remark") = Remark
dr("OrderedTimes") = OrderedTimes
dt.Rows.Add(dr) '<-------- เพิ่มข้อมูลใหม่ในObj dt
Dim combd As New OleDbCommandBuilder(da)
da.Update(ds, "IT_TransContractor") ' <---------------------------------ERROR ตรงนี้อ่ะครับ ตามรูปแรก
ds.AcceptChanges()
da.Fill(ds, "IT_TransContractor")
End Sub
Tag : .NET, Ms Access, Win (Windows App), VS 2010 (.NET 4.x), Windows