944,129 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 11348
  • VB.NET RSS
Jun 25th, 2006
0

move previouse record in VB.net

Expand Post »
Hi All,

i facing problem here, the following is my coding for move previouse recored.

'Open connection
ConnCust = New ADODB.Connection
Cust_String = "Provider=Microsoft.JET.OLEDB.4.0;data source=\\AAA\ABC.mdb"
ConnCust.Open(Cust_String)
'Open recordset from Customer List
RstCust = New ADODB.Recordset
Last_SQL = "SELECT * FROM CustomerList WHERE CustomerID <= " & lblCustID.Text & " ORDER BY CustomerID"
RstCust = ConnCust.Execute(Last_SQL)
With RstCust
If Not .EOF And Not .BOF Then
If RstCust("CustomerID").Value = lblCustID.Text Then
.MovePrevious()
If .BOF Then
MsgBox("Begining of record list!", vbExclamation, "Customer Entry Record")
.MoveFirst()
End If
End If
Call Retrieve_Data()
Else
.Close()
ConnCust.Close()
'load first record
Call Load_First_Saved_Record()
Exit Sub
End If
Call Record_Exist()
'Close recordset
.Close()
End With
'Close connection
ConnCust.Close()
'Dereference recordset and connection
RstCust = Nothing
ConnCust = Nothing

when i try to running the program there have error in
.MovePrevious() line. The error message are: -

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in ABC.exe
Additional information: Operation is not allowed in this context.

can anyone help me in this? thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
khwo is offline Offline
12 posts
since Jun 2006
Jun 26th, 2006
0

Re: move previouse record in VB.net

Hi

Why don't you try something different: evaluate the number of records instead of identifying if ou are at the beginning or at the end of the recordset.

another thing is that the recordst will start at the beginning, so if the first action is move to the previous record, you will get an error.

If there are records, then move to the previous one, but make sure you go to the last one first.

VB.NET Syntax (Toggle Plain Text)
  1. 'Open connection
  2. ConnCust = New ADODB.Connection
  3. Cust_String = "Provider=Microsoft.JET.OLEDB.4.0;data source=\\AAA\ABC.mdb"
  4. ConnCust.Open(Cust_String)
  5. 'Open recordset from Customer List
  6. RstCust = New ADODB.Recordset
  7. Last_SQL = "SELECT * FROM CustomerList WHERE CustomerID <= " & lblCustID.Text & " ORDER BY CustomerID"
  8. RstCust = ConnCust.Execute(Last_SQL)
  9.  
  10. With RstCust
  11.  
  12. if RstCust.RecordCount = 0 then
  13. .Close()
  14. ConnCust.Close()
  15. 'load first record
  16. Call Load_First_Saved_Record()
  17. Exit Sub
  18. end if
  19.  
  20. If RstCust("CustomerID").Value = lblCustID.Text Then
  21. if not .BOF
  22. .Movelast()
  23. .MovePrevious()
  24. else
  25. MsgBox("Begining of record list!", vbExclamation, "Customer Entry Record")
  26. End If
  27. End If
  28. Call Retrieve_Data()
  29. end if
  30. end with

i think that will do it.

regards
Reputation Points: 23
Solved Threads: 10
Junior Poster
williamrojas78 is offline Offline
111 posts
since Jun 2005
Jun 26th, 2006
0

Re: move previouse record in VB.net

hi williamrojas78,

I have use your code but still cannot work. still error there. do u have any code that to call the previouse record? if yes can u give me some example? thanks.

the error are:-

when i try to running the program there have error in .MoveLast() and .MovePrevious() line. The error message are: -

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in ABC.exe

Additional information: Rowset does not support fetching backward.

can give some advice?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
khwo is offline Offline
12 posts
since Jun 2006
Jun 27th, 2006
0

Re: move previouse record in VB.net

I just tried the code here and it works. I don't understand.

The ADO component that you added to your references: is it a .NET type or a Com type?

I thinks that is your problem, maybe the COM component does not support the methods. Try selecting the .NET component instead.

mine is located at:
C:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll

regards
Reputation Points: 23
Solved Threads: 10
Junior Poster
williamrojas78 is offline Offline
111 posts
since Jun 2005
Jun 27th, 2006
0

Re: move previouse record in VB.net

hi williamrojas78,

i try to add the .NET component which located at:
C:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll but still cannot work.

inside my project i have the following reference:-
1) adodb1
2) CrystallDecisions.CrystallReports.Engine
3) CrystallDecisions.ReportSOurce
4) CrystallDecisions.Shared
5) System
6) System.Data
7) System.Drawing
8) System.Windows.Forms
9) System.XML

and inside my form i have imports the following thing:-
1) Imports System.Data
2) Imports System.Data.OleDb
3) Imports ADODB

and i have 2 variable which are:-
Dim
ConnCust As ADODB.Connection
Dim RstCust As ADODB.Recordset

which mistake i have done? pls give some advice. thanks.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
khwo is offline Offline
12 posts
since Jun 2006
Jun 28th, 2006
0

Re: move previouse record in VB.net

Hi

Try using this connection instead:

VB.NET Syntax (Toggle Plain Text)
  1. 'define this variable where connection and recordset variables are defined
  2. dim cmdCommand As New ADODB.Command
  3.  
  4.  
  5.  
  6. '---------------------------------------------------------------
  7. ConnCust = New ADODB.Connection
  8.  
  9. ConnCust.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\AAA\ABC.mdb;Mode=Read|Write"
  10. ConnCust.CursorLocation = ADODB.CursorLocationEnum.adUseClient
  11. ConnCust.Open()
  12.  
  13.  
  14. With cmdCommand
  15. .let_ActiveConnection(conConnectionVh)
  16. .CommandText = "SELECT * FROM CustomerList ;"
  17. .CommandType = ADODB.CommandTypeEnum.adCmdText
  18. End With
  19.  
  20. With RstCust
  21. .CursorType = ADODB.CursorTypeEnum.adOpenStatic
  22. .CursorLocation = ADODB.CursorLocationEnum.adUseClient
  23. .LockType = ADODB.LockTypeEnum.adLockOptimistic
  24. .Open(cmdCommand)
  25. End With

I think the commandtext for your connection is blocking this option.
Other than that i don't know.

Hope it helps.
Reputation Points: 23
Solved Threads: 10
Junior Poster
williamrojas78 is offline Offline
111 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: How to display Excel file in a tabPage?
Next Thread in VB.NET Forum Timeline: error : Could not access CDO.Message object





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC