Confussing error .. help needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Newman

    #1

    Confussing error .. help needed

    when I load a form I create a dateaset using
    (part of sub )
    Orig_Accounts = GetSQLDataSet(" EXEC
    BossData.dbo.SQ L2005_ORIGACCOU NTS", "TBL_OrigAccoun ts")
    ' Set Primary Keys
    SearchKey(0) =
    Orig_Accounts.T ables("TBL_Orig Accounts").Colu mns("tblOA_Lice nce")
    SearchKey(1) =
    Orig_Accounts.T ables("TBL_Orig Accounts").Colu mns("tblOA_Acco untID")
    Orig_Accounts.T ables("TBL_Orig Accounts").Prim aryKey = SearchKey

    (end part of sub )

    I then call SearchRecord using LicenceNumber & "001" to display the 1st
    account for that licence number. this all works fine. I load all the account
    id's ( 001,002 003 etc ) into a combobox using the sub LoadcmboAccount ID.
    The idea is that the operator can use the combobox and select an account id
    it will display that record. However when the use selects an Id and i call
    the SearchRecord(sL icence, cmboAccountID.T ext) sub , SLicence being the
    licence number and cmboAccountID.T ext being the selected ID from the combo
    list. I keep getting this error

    Column 'tblOA_Licence, tblOA_AccountID ' is constrained to be unique. Value
    '217514, 005' is already present.

    and i dont understand why... the sub works fine when the form is loaded,
    but as soon as you try and use it a second time you get that error. Stepping
    through the code it is causing an error at the
    Manager.Positio n = ACTIVEROW line, any ideas why ?



    SUB

    Private ACTIVEROW As Integer = 0
    Private SearchRow As DataRow
    Dim FindMatch(1) As Object


    Private Sub SearchRecord(By Val Licence As String, ByVal AccountID As
    String)
    Try
    FindMatch(0) = Licence
    FindMatch(1) = AccountID
    SearchRow =
    Orig_Accounts.T ables("TBL_Orig Accounts").Rows .Find(FindMatch )
    ACTIVEROW = CInt(SearchRow( "idCol").ToStri ng)
    If ACTIVEROW 0 Then
    LoadControls(AC TIVEROW)
    Manager.Positio n = ACTIVEROW
    End If
    Catch ex As Exception
    Console.WriteLi ne(ex.Message)
    End Try
    End Sub

    Private Sub LoadcmboAccount ID()
    SQL_COMMAND.Com mandText = "Select TblOA_AccountID from
    Bossdata.dbo.Or iginatingAccoun ts where tbloa_licence = '" & sLicence & "'
    Order by Tbloa_AccountId "
    SQL_COMMAND.Con nection = BOSSSQLCONNECTI ON
    SQL_DATAREADER = SQL_COMMAND.Exe cuteReader
    Do While SQL_DATAREADER. Read
    If SQL_DATAREADER. GetString(0) cmboAccountID.T ext Then
    cmboAccountID.I tems.Add(SQL_DA TAREADER.GetStr ing(0))
    End If
    Loop
    End Sub

  • Chris Dunaway

    #2
    Re: Confussing error .. help needed

    Peter Newman wrote:
    >
    Column 'tblOA_Licence, tblOA_AccountID ' is constrained to be unique. Value
    '217514, 005' is already present.
    >
    On casual inspection of your code, I can't see what might be causing
    that exception. But apparently you have a unique constraint on the
    License and AccountID columns of your table and for some reason you are
    inserting another record with that same combination of License and
    AccountID.

    You will have to figure out why you are inserting a new record with
    those same values.

    Comment

    Working...