move previouse record in VB.net

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2006
Posts: 12
Reputation: khwo is an unknown quantity at this point 
Solved Threads: 0
khwo khwo is offline Offline
Newbie Poster

move previouse record in VB.net

 
0
  #1
Jun 25th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 85
Reputation: williamrojas78 is an unknown quantity at this point 
Solved Threads: 4
williamrojas78's Avatar
williamrojas78 williamrojas78 is offline Offline
Junior Poster in Training

Re: move previouse record in VB.net

 
0
  #2
Jun 26th, 2006
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.

  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
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 12
Reputation: khwo is an unknown quantity at this point 
Solved Threads: 0
khwo khwo is offline Offline
Newbie Poster

Re: move previouse record in VB.net

 
0
  #3
Jun 26th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 85
Reputation: williamrojas78 is an unknown quantity at this point 
Solved Threads: 4
williamrojas78's Avatar
williamrojas78 williamrojas78 is offline Offline
Junior Poster in Training

Re: move previouse record in VB.net

 
0
  #4
Jun 27th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 12
Reputation: khwo is an unknown quantity at this point 
Solved Threads: 0
khwo khwo is offline Offline
Newbie Poster

Re: move previouse record in VB.net

 
0
  #5
Jun 27th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 85
Reputation: williamrojas78 is an unknown quantity at this point 
Solved Threads: 4
williamrojas78's Avatar
williamrojas78 williamrojas78 is offline Offline
Junior Poster in Training

Re: move previouse record in VB.net

 
0
  #6
Jun 28th, 2006
Hi

Try using this connection instead:

  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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC