G
Guest
when I load a form I create a dateaset using
(part of sub )
Orig_Accounts = GetSQLDataSet("EXEC
BossData.dbo.SQL2005_ORIGACCOUNTS", "TBL_OrigAccounts")
' Set Primary Keys
SearchKey(0) =
Orig_Accounts.Tables("TBL_OrigAccounts").Columns("tblOA_Licence")
SearchKey(1) =
Orig_Accounts.Tables("TBL_OrigAccounts").Columns("tblOA_AccountID")
Orig_Accounts.Tables("TBL_OrigAccounts").PrimaryKey = 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 LoadcmboAccountID.
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(sLicence, cmboAccountID.Text) sub , SLicence being the
licence number and cmboAccountID.Text 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.Position = ACTIVEROW line, any ideas why ?
SUB
Private ACTIVEROW As Integer = 0
Private SearchRow As DataRow
Dim FindMatch(1) As Object
Private Sub SearchRecord(ByVal Licence As String, ByVal AccountID As
String)
Try
FindMatch(0) = Licence
FindMatch(1) = AccountID
SearchRow =
Orig_Accounts.Tables("TBL_OrigAccounts").Rows.Find(FindMatch)
ACTIVEROW = CInt(SearchRow("idCol").ToString)
If ACTIVEROW > 0 Then
LoadControls(ACTIVEROW)
Manager.Position = ACTIVEROW
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Private Sub LoadcmboAccountID()
SQL_COMMAND.CommandText = "Select TblOA_AccountID from
Bossdata.dbo.OriginatingAccounts where tbloa_licence = '" & sLicence & "'
Order by Tbloa_AccountId"
SQL_COMMAND.Connection = BOSSSQLCONNECTION
SQL_DATAREADER = SQL_COMMAND.ExecuteReader
Do While SQL_DATAREADER.Read
If SQL_DATAREADER.GetString(0) > cmboAccountID.Text Then
cmboAccountID.Items.Add(SQL_DATAREADER.GetString(0))
End If
Loop
End Sub
(part of sub )
Orig_Accounts = GetSQLDataSet("EXEC
BossData.dbo.SQL2005_ORIGACCOUNTS", "TBL_OrigAccounts")
' Set Primary Keys
SearchKey(0) =
Orig_Accounts.Tables("TBL_OrigAccounts").Columns("tblOA_Licence")
SearchKey(1) =
Orig_Accounts.Tables("TBL_OrigAccounts").Columns("tblOA_AccountID")
Orig_Accounts.Tables("TBL_OrigAccounts").PrimaryKey = 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 LoadcmboAccountID.
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(sLicence, cmboAccountID.Text) sub , SLicence being the
licence number and cmboAccountID.Text 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.Position = ACTIVEROW line, any ideas why ?
SUB
Private ACTIVEROW As Integer = 0
Private SearchRow As DataRow
Dim FindMatch(1) As Object
Private Sub SearchRecord(ByVal Licence As String, ByVal AccountID As
String)
Try
FindMatch(0) = Licence
FindMatch(1) = AccountID
SearchRow =
Orig_Accounts.Tables("TBL_OrigAccounts").Rows.Find(FindMatch)
ACTIVEROW = CInt(SearchRow("idCol").ToString)
If ACTIVEROW > 0 Then
LoadControls(ACTIVEROW)
Manager.Position = ACTIVEROW
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Private Sub LoadcmboAccountID()
SQL_COMMAND.CommandText = "Select TblOA_AccountID from
Bossdata.dbo.OriginatingAccounts where tbloa_licence = '" & sLicence & "'
Order by Tbloa_AccountId"
SQL_COMMAND.Connection = BOSSSQLCONNECTION
SQL_DATAREADER = SQL_COMMAND.ExecuteReader
Do While SQL_DATAREADER.Read
If SQL_DATAREADER.GetString(0) > cmboAccountID.Text Then
cmboAccountID.Items.Add(SQL_DATAREADER.GetString(0))
End If
Loop
End Sub