0

それらの違いは何ですか、最初のものは本当に速く実行されますか?

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

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

列がテーブル テーブルに属していません/テーブル 0 が見つかりません

小さな Web アプリケーションで問題が発生しています。2 人のユーザーが同時にレコードの追加と更新を行っている場合。

「列がテーブル テーブルに属していないことがあり、テーブル 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

このコードは、レコードを呼び出すためのものです。

Dim oDocument As New 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オブジェクトのプロパティを反復処理することです。配列の反復には使用しないでください。の詳細については、この MDN の記事を参照してくださいfor .. in。さらに、for .. inループは、それらのプロパティを反復する順序を保証しません。

通常の for ループを使用して、ie を反復処理できます。配列。要素の順序を保持します。

于 2013-08-30T08:39:36.587 に答える