0

它们之间有什么区别,第一个真的跑得更快吗?

for (x in myArray) {
    document.write(myArray[x] + "<br />")
}

for (i=0; i<myArray.length; i++) { 
    document.write(myArray[i] + "<br />")
}

列不属于表 Table/找不到表 0

我的小型 Web 应用程序出现问题。当两个用户同时添加记录和更新时。

出现错误“列不属于表 Table 有时找不到表 0。” 我不知道从哪里开始。请帮我。我已经创建了一个库,就在这里。

我的 ApplicationTool 类。

Private oSqlConnection As SqlConnection
Private oSqlDataAdapter As SqlDataAdapter
Private oSqlCommand As SqlCommand
Private oSqlTransaction As SqlTransaction
Public Dr As DataRow
Public Ds As DataSet

Private _strCommand As String

Public Property strCommand() As String
    Get
        Return _strCommand
    End Get

    Set(ByVal value As String)
        If Not InTransaction Then RollBack_Transaction()
        _strCommand = "SET DATEFORMAT mdy " & vbCrLf & value
        DbQuery()
    End Set
End Property

Protected Sub DbQuery()

    If Not InTransaction Then
        RollBack_Transaction()

        oSqlCommand = New SqlCommand(_strCommand, oSqlConnection)
    Else
        oSqlCommand = oSqlConnection.CreateCommand
        If _InTransaction_Initial Then
            oSqlConnection.Open()
            oSqlTransaction = oSqlConnection.BeginTransaction(IsolationLevel.ReadCommitted)
            _InTransaction_Initial = False
        End If

        oSqlCommand.Transaction = oSqlTransaction
        oSqlCommand.CommandText = _strCommand
        oSqlCommand.CommandTimeout = 0
    End If

    oSqlDataAdapter = New SqlDataAdapter(oSqlCommand)
    Ds = New DataSet
    oSqlDataAdapter.Fill(Ds)

End Sub

Private _InTransaction_Initial As Boolean = False
Private InTransaction As Boolean

Public Sub StartTransaction()
    _InTransaction_Initial = True
    InTransaction = True
End Sub
Public Sub RollBack_Transaction()
    Try
        oSqlTransaction.Rollback()
    Catch ex As Exception
    End Try
    Try
        oSqlConnection.Close()
    Catch ex As Exception
    End Try

    InTransaction = False
End Sub

Public Sub Commit_Transaction()
    Try
        oSqlTransaction.Commit()
    Catch ex As Exception
    End Try
    Try
        oSqlConnection.Close()
    Catch ex As Exception
    End Try

    InTransaction = False
End Sub

Function dsCount() As Long
    Return Ds.Tables(0).Rows.Count
End Function

Public Sub New()
    oSqlConnection = New SqlConnection("initial catalog=" & MainDb & "; data source=" & ServerName & "; user id=" & SqlID & "; password=" & SqlPassword & "; Application Name=APPTech-MIMS-Web; Connection Timeout=30")
    Dim oString As String = oSqlConnection.ConnectionString
    FileDbName = GetConfigKey("FileDb")
End Sub

我的文档类。

Public Class oDocuments
Inherits ApplicationTool


Public AppId As Long = -1 
Public AppType As oAppTypes = Nothing
Public DocNum As String

Public DocDate As DateTime
Public RefNum As String
Public PriceList As Long
Public CardCode As String
Public CardName As String
Public WhsCode As String
Public ToWhsCode As String
Public BinCode As String
Public ToBinCode As String

Public DocStatus As oDocStatuses = oDocStatuses.New_Record

Public SubmittedDate As DateTime
Public SubmittedBy As Long
Public CreatedBy As Long = GetUSER_ID

Public Lines As New oDocuments_Lines
Public Distribution As New oDocuments_Distribution

Private oDistribution As Boolean = False


Sub New(Optional ByVal oAppType As oAppTypes = Nothing, Optional ByVal oSerial As Boolean = False)
    If Not IsNothing(oAppType) Then AppType = oAppType
    Lines.Apptype = AppType
    Distribution.AppType = AppType

    If oSerial Then
        oDistribution = True
    End If
End Sub

Function ValidateData() As Boolean
    Try

        If IsNothing(AppType) Or AppType = 0 Then SetMessage("Invalid application type.", oMessageTypes.oError) : Return False

        Return True
    Catch ex As Exception
        SetMessage(ex)
    End Try
    Return False
End Function

Private oDs As DataSet
Public ReadOnly Property Count() As Integer
    Get
        Return oDs.Tables(0).Rows.Count
    End Get
End Property

Function GetRecordSet() As Data.DataTable
    Return Ds.Tables(0)
End Function

Private Function SetVariables() As Boolean
    oDs = Ds.Copy
    Dim hasData As Boolean = False

    If dsCount() > 0 Then
        AppId = GetDs("AppId") 
        AppType = GetDs("AppType")

        DocNum = GetDs("DocNum")
        DocDate = GetDs("DocDate")
        PriceList = GetDs("PriceList")
        WhsCode = GetDs("WhsCode")
        ToWhsCode = GetDs("ToWhsCode")
        BinCode = GetDs("BinCode")
        ToBinCode = GetDs("ToBinCode")
        RefNum = GetDs("RefNum")
        CardCode = GetDs("CardCode")
        CardName = GetDs("CardName")

        DocStatus = GetDs("DocStatus")

        SubmittedDate = IIf(IsDBNull(GetDs("SubmittedDate")), Now, GetDs("SubmittedDate"))
        SubmittedBy = GetDs("SubmittedBy")
        CreatedBy = GetDs("CreatedBy")

        hasData = True
    End If

    Return hasData
End Function


Function GetByAppId(ByVal oAppId As Long) As Boolean
    Try
        strCommand = "SELECT Top 1 * FROM " & GetTableName(AppType, oTableLevel.Header) & "(nolock) WHERE AppId = '" & oAppId & "'"

        Return SetVariables()
    Catch ex As Exception
        SetMessage(ex)
    End Try
    Return False
End Function

Function Add() As Boolean
    Try
        If Not ValidateData() Then Return False

        GetNextNumber(AppType)
        AppId = GetNewAppId

        If Not Update Then
            Return False

        End If

        Return True
    Catch ex As Exception
        SetMessage(ex)
    End Try
End Function

Function Update() As Boolean
    Try
        If Not ValidateData() Then Return False

        strCommand = "UPDATE " & GetTableName(AppType, oTableLevel.Header) & " SET " & _
                    "DocNum = '" & TrimData(DocNum) & "', " & _
                    "DocDate = '" & TrimData(DocDate) & "', " & _
                    "RefNum = '" & TrimData(RefNum) & "', " & _
                    "PriceList = '" & TrimData(PriceList) & "', " & _
                    "WhsCode = '" & TrimData(WhsCode) & "', " & _
                    "ToWhsCode = '" & TrimData(ToWhsCode) & "', " & _
                    "BinCode = '" & TrimData(BinCode) & "', " & _
                    "ToBinCode = '" & TrimData(ToBinCode) & "', " & _
                    "CardCode = '" & TrimData(CardCode) & "', " & _
                    "CardName = '" & TrimData(CardName) & "', " & _
                    "ModifiedDate = GETDATE(), " & _
                    "ModifiedBy = '" & GetUSER_ID & "' " & _
                    "WHERE AppId = '" & AppId & "' "

        Return True
    Catch ex As Exception
        SetMessage(ex)
    End Try
End Function

Function Submit() As Boolean
    Try
        If Not ValidateAppId(AppId) Then Return False

        Return ChangeDocStatus(AppType, AppId, oDocStatuses.Submitted)
    Catch ex As Exception
        SetMessage(ex)
    End Try
    Return False
End Function

结束类

当他们添加或更新数据时,在我的代码后面。

Private Function SaveDocument() As Boolean Dim oDocument As New WEB_Library.oDocuments(AppType.Text)

    With oDocument
        .AppId = AppId.Text
        .DocNum = AppId.Text
        .RefNum = RefNum.Text
        .PriceList = -1
        .WhsCode = WhsCode.Text

        .BinCode = BinCode.Text
        .CardCode = CardCode.Text
        .CardName = CardName.Text
        .ToWhsCode = ToWhsCode.Text

        If AppId.Text = "-1" Then
            If .Add Then
                AppId.Text = .GetNewAppId
                DocNum.Text = .GetNewAppId

                Return True
            End If

        Else
            If .Update Then
                Return True

            End If

        End If
    End With
End Function

此代码用于调用记录。

将 oDocument 变暗为新 WEB_Library.oDocuments(AppType.Text)

        With oDocument
            If .GetByAppId(DocNum.Text) Then
                AppId.Text = .AppId
                DocNum.Text = .AppId
                DocDate.Text = .DocDate
                WhsCode.Text = .WhsCode
                BinCode.Text = .BinCode
                CardCode.Text = .CardCode
                CardName.Text = .CardName
                ToWhsCode.Text = .ToWhsCode
                DocStatus.Text = .DocStatus
                PriceList.Text = .PriceList
                ToWhsCode.Text = .ToWhsCode
                ToBinLoc.Text = .ToBinCode
                RefNum.Text = .RefNum
            Else
                DocDate.Text = ""
                WhsCode.Text = "-1"
                BinCode.Text = "-1"
                CardCode.Text = "-1"
                CardName.Text = "-1"
                ToWhsCode.Text = "-1"
                DocStatus.Text = "-1"
                PriceList.Text = "-1"
                ToWhsCode.Text = "-1"
                ToBinLoc.Text = "-1"
                RefNum.Text = ""
            End If

        End With

        Select Case DocStatus.Text = "-1"
            Case -1
                cmdSubmit.Visible = True

            Case 2
                cmdSubmit.Visible = False

        End Select

        Call SetGrid()

然后在网格中绑定。

Sub SetGrid()
    Try
        Dim oDocument As New WEB_Library.oDocuments(AppType.Text)
        gMain.DataSource = Nothing
        gMain.DataBind()


        If oDocument.GetByAppId(AppId.Text) Then

            gMain.DataSource = oDocument.Lines.GetRecordSet.DefaultView
            gMain.DataBind()

            Dim cmbItemCode As New DropDownList
            cmbGetItemCode(cmbItemCode)

            Dim dgObj As DataGrid = gMain

            For Each oGridItem In dgObj.Items
                Dim ItemCode As DropDownList = oGridItem.FindControl("ItemCode")
                If oDocument.Lines.GetByLineId(dgObj.DataKeys(oGridItem.ItemIndex)) Then
                    Dim InvQty As AppTextBox = oGridItem.FindControl("InvQty")

                    WebCtrl.cmbCopyDataBind(cmbItemCode, ItemCode)
                    WebCtrl.cmbFocusValue(ItemCode, oDocument.Lines.ItemCode)

                End If
            Next
        End If
    Catch ex As Exception
        WebCtrl.SetMessage(ex, WEB_Library.ApplicationTool.oMessageTypes.oError)
    End Try
End Sub

希望听到积极的回应。我在我的所有 WEB 应用程序中都在努力解决这个问题。:(

谢谢你。

4

1 回答 1

1

x in y循环是关于迭代对象的属性。它不应该用于迭代数组。有关. _ _ for .. in此外,for .. in循环不会保证它迭代这些属性的任何顺序。

常规的 for 循环可用于迭代 ie。数组。它将保留元素的顺序。

于 2013-08-30T08:39:36.587 回答