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
(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
Comment