0
これらのコードを使用して、データベースに異なるアピール数を追加します。各アピール番号には、これらのコードを介して割り当てられた割り当てコードがあります。
問題:
問題は、私は同時に2人の以上の控訴を追加するときに、このコードは唯一の追加第一の魅力に割り当て、割り当てコードを検出したが、次の追加割り当て数を検出しないです。
私の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
***決してEVER ***のような何かを行う 'SELECT MAX(...)+ 1 '「次の最も高い」ID番号を取得するには - これは、システムで***ちょうど***安全ではありません複数のユーザー!データベースがこれを処理するようにしてください。これらの種類のカウンタには、MS Accessの 'Autonumber'やSQL Serverの' INT IDENTITY'カラムの自動ナンバリングを使用してください。自分のロールを出そうとしないでください - データベースの内容を使用しないでください! –
お返事ありがとうございます。 –
どうすれば私の目的を達成できるのか教えてください。 Select MAX(..)は、データベース内の別のテーブルから次に高いIDの値を取得するために使用されます。他のテーブルから最高の値を取得するのに適したコマンドです。 –