背景:
通过这些代码,我向数据库添加了不同的申诉号码。每个上诉号码都有一个通过这些代码分配给它的分配代码。
问题:
问题是,当我同时添加2个以上的上诉时,此代码仅检测分配给第1次上诉的分配代码,但不检测下一个添加的分配编号。
我尝试添加Thread.sleep方法,但结果是一样的。
Try
' Find out last assignment code
Dim fillCommand As String
Dim FillList As New OleDb.OleDbDataAdapter
Dim dt As New DataTable
Dim rowdata As Integer
Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\ComplianceDB.accdb;Jet OLEDB:Database Password=xxxxxxx;" 'D:\Important Programing links\Programming Learning\Compliance Diary\ComlianceDiary\ComlianceDiary\database\ComplianceDB.accdb"
Dim Conn As New OleDb.OleDbConnection(ConnString)
Conn.Open()
If ListView1.Items.Count = 0 Then
MessageBox.Show("Please enter valid information to add appeal.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf BenchComboBox.Text = "" Or NoticeLocationTextBox.Text = "" Or BenchMembersTextBox.Text = "" Then
MessageBox.Show("Please enter all the required information to add appeal.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
For i = 0 To ListView1.Items.Count - 1
'Add Appeals to ATIR list
Me.ATIRTableAdapter.Insert(ClientComboBox.Text, ListView1.Items(i).SubItems.Item(1).Text, ListView1.Items(i).Text, ListView1.Items(i).SubItems.Item(2).Text, BenchComboBox.Text, BenchMembersTextBox.Text, HearingDate.Value.Date, ListView1.Items(i).SubItems.Item(4).Text, mgrComboBox.Text, txtdescription.Text, ListView1.Items(i).SubItems.Item(3).Text, NoticeLocationTextBox.Text, ChangePassword.GUIDTextBox.Text, DateAndTime.Today)
Dim AssignmentCommand = New OleDbCommand("select AssignmentCode, AssignmentName from Assignment where AssignmentName = 'ATIR Appeal - " & ListView1.Items(i).Text & "' AND ClientName = '" & ClientComboBox.Text & "'", Conn) ' (select max(AssignmentCode) from Assignment)" 'SELECT * FROM Assignment Where AssignmentName = '" & AssignmentNameTextBox.Text & "' AND ClientName = '" & ClientNameComboBox.Text & "'" ' WHERE DateofHearing BETWEEN " & Today.Date & " AND " & Today.Date.AddDays(15)
Dim Reader As OleDbDataReader = AssignmentCommand.ExecuteReader
'Check if the assignment name already exists, if yes, fetch old assignment code and add it to new compliance
If Reader.Read Then
Dim ATIRCodeCmd = New OleDbCommand("select ID from ATIR where ID = (select max(ID) from ATIR)", Conn) 'SELECT * FROM Assignment Where AssignmentName = '" & AssignmentNameTextBox.Text & "' AND ClientName = '" & ClientNameComboBox.Text & "'" ' WHERE DateofHearing BETWEEN " & Today.Date & " AND " & Today.Date.AddDays(15)
Dim ReaderATIRCode As OleDbDataReader = ATIRCodeCmd.ExecuteReader
While ReaderATIRCode.Read()
Me.NoticeComplianceTableAdapter1.Insert(ClientComboBox.Text, Reader.Item(1).ToString, Today.Date, Today.Date, Reader.Item(1).ToString, NoticeLocationTextBox.Text, txtdescription.Text, Reader.Item(0).ToString, "No", "", "", "Pending", ListView1.Items(i).SubItems.Item(1).Text, "", "", "", "Fresh Notice", "", "", ChangePassword.GUIDTextBox.Text, DateAndTime.Today, mgrComboBox.Text, PartnerNameTextBox.Text, SrManagerNameTextBox.Text, "AppellateCompliance", HearingDate.Value.Date, "", "", "", "", "", ReaderATIRCode.Item(0).ToString, "ATIR")
End While
Else
'if assignment does not exists, then create a new one and give new assignment number to new compliance.
Me.AssignmentTableAdapter1.Insert(ListView1.Items(i).SubItems.Item(1).Text, ClientComboBox.Text, "ATIR Appeal - " & ListView1.Items(i).Text, "N/A", "Pending", "No", Today.Date, HearingDate.Value.Date, HearingDate.Value.Date, mgrComboBox.Text, SrManagerNameTextBox.Text, PartnerNameTextBox.Text, "Income Tax Ordinance, 2001", "Pending", "", "Pending", "", "Pending", "", Today.Date, "", Today.Date, "Pending", Today.Date, "")
Dim AssignmentCodeCmd = New OleDbCommand("select AssignmentCode from Assignment where AssignmentCode = (select max(AssignmentCode) from Assignment)", Conn) 'SELECT * FROM Assignment Where AssignmentName = '" & AssignmentNameTextBox.Text & "' AND ClientName = '" & ClientNameComboBox.Text & "'" ' WHERE DateofHearing BETWEEN " & Today.Date & " AND " & Today.Date.AddDays(15)
Dim ReaderCode As OleDbDataReader = AssignmentCodeCmd.ExecuteReader
While ReaderCode.Read()
rowdata = ReaderCode.Item(0).ToString
ReaderCode.NextResult()
End While
Dim ATIRCodeCmd = New OleDbCommand("select ID from ATIR where ID = (select max(ID) from ATIR)", Conn) 'SELECT * FROM Assignment Where AssignmentName = '" & AssignmentNameTextBox.Text & "' AND ClientName = '" & ClientNameComboBox.Text & "'" ' WHERE DateofHearing BETWEEN " & Today.Date & " AND " & Today.Date.AddDays(15)
'Thread.Sleep(1000)
Dim ReaderATIRCode As OleDbDataReader = ATIRCodeCmd.ExecuteReader
While ReaderATIRCode.Read()
Me.NoticeComplianceTableAdapter1.Insert(ClientComboBox.Text, "ATIR Appeal - " & ListView1.Items(i).Text, Today.Date, Today.Date, "ATIR Appeal - " & ListView1.Items(i).Text, NoticeLocationTextBox.Text, txtdescription.Text, rowdata, "No", "", "", "Pending", ListView1.Items(i).SubItems.Item(1).Text, "", "", "", "Fresh Notice", "", "", ChangePassword.GUIDTextBox.Text, DateAndTime.Today, mgrComboBox.Text, PartnerNameTextBox.Text, SrManagerNameTextBox.Text, "AppellateCompliance", HearingDate.Value.Date, "", "", "", "", "", ReaderATIRCode.Item(0).ToString, "ATIR")
End While
End If
Reader.Close()
Next
MessageBox.Show("ATIR Appeal(s) have been noted.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
Conn.Close()
Me.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
答案 0 :(得分:0)
没关系。我使用@@IDENTITY
sql命令解决了我的问题。谢谢大家的贡献。