插入数据升序排序

时间:2017-12-11 03:18:24

标签: vb.net sorting access-vba insertion-sort

我有案例我想用datetime将数据插入数据库, 当iam将数据插入数据库时​​,数据不像我预期的那样排序

我的期望 A1 a2 A3 A4 B1 B2 B3 B4

我得到了什么 A1 a2 B1 B2 B3 B4 A3 A4

这是我目前的代码(sharpdevelop)vb语言

Dim connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Journal Entry\Database\jentry_db.mdb;Persist Security Info=False")   
        connection.Open         
            Try
                Dim transaction As OleDbTransaction = connection.BeginTransaction
                Try
                    For Each DetailRowLL As DataRow In DetailsTableLL.Rows
                    Dim command2 As New OleDbCommand("INSERT INTO T_TransactionsAccrualDetails (AccrualNo, GLAccountID, PCCodeID, JournalClass, [Amount], Description, [DateIn])" & _
                    " VALUES (@AccrualNoParam2LL, @GLAccountIDParam2LL, @PCCodeIDParam2LL, @JournalClassParam2LL, @AmountParam2LL, @DescriptionParam2LL, @DateInParam2LL)", connection, transaction)
                    command2.Parameters.Add("@AccrualNoParam2LL", DetailRowLL.Item("AccrualNo"))
                    command2.Parameters.Add("@GLAccountIDParam2LL", DetailRowLL.Item("GLAccountID"))
                    command2.Parameters.Add("@PCCodeIDParam2LL", DetailRowLL.Item("PCCodeID"))
                    command2.Parameters.Add("@JournalClassParam2LL", DetailRowLL.Item("JournalClass"))
                    command2.Parameters.Add("@AmountParam2LL", DetailRowLL.Item("Amount"))
                    command2.Parameters.Add("@DescriptionParam2LL", DetailRowLL.Item("Description"))
                    command2.Parameters.Add("@DateInParam2LL", DetailRowLL.Item("DateIn"))
                    command2.ExecuteNonQuery()
                    Next
                    transaction.Commit
                    TempTableLL.clear

                Catch ex As Exception
                    MessageBox.Show("Error", ex.Message & vbCrLf & ex.StackTrace, MessageBoxButtons.OK, MessageBoxIcon.Error)   
                    transaction.Rollback
                    Exit Sub
                End Try         
            Finally
                connection.Close
            End Try
                ResetLL()
                MsgBox("Success")
                Exit Sub
              Catch ex As Exception
                MessageBox.Show("Error", ex.Message & vbCrLf & ex.StackTrace, MessageBoxButtons.OK, MessageBoxIcon.Error)   
              End Try 

@Tetsuya 这个用于插入数据表的代码,对于masterdata PCCODELL的FYI已经排序ASC所以我需要改变或做什么?

Me.LL_txtTotalAllocation.Text = Format(CDbl(LL_txtAmount.Text - lngTotal).ToString("N2"))
        strGetAccrualAllocation = Me.LL_txtTotalAllocation.Text
            Dim adapter As New OleDbDataAdapter("SELECT PCCODELL.* FROM PCCODELL ORDER BY PCCODELL.PCCodeID ASC", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Journal Entry\Database\jentry_db.mdb;Persist Security Info=False")
            Dim table As New DataTable
            adapter.Fill(table)

            For Each row As DataRow In table.Rows
                Dim newRow As DataRow = DetailsTableLL.NewRow
                newRow("AccrualNo") = strLLAccrualNo
                newRow("GLAccountID") = "83101002"
                newRow("PCCodeID") =  row("PCCodeID")
                newRow("JournalClass") = "R"
                newRow("Description") = strGetDescriptionLL
                newRow("Amount") = -CDbl(row("PERCENTAGE")) * Double.Parse(strGetAccrualAllocation) 'Format( -1 * CDbl(row("PERCENTAGE") * strGetAccrualAllocation).ToString("N2"))
                newRow("DateIn") = Now.ToString()
                DetailsTableLL.Rows.Add(newRow)
                Thread.Sleep(interval)
            Next
            BindDetailsLL

0 个答案:

没有答案