Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

move through from row to row

Status
Not open for further replies.

T3x

Technical User
Sep 23, 2003
11
LK
is there a way like in vb6(recordset.movenext) to move through in asp.net so a person can manually go through rows(both forword and backword)and display them on a form.
 
Backwards cannot be done in ADO.net without the creation of an offline dataset - creating a datareader is easy for forward-only reads.

You will need to create a dataadapter, and use it to fill a dataset which you can then navigate freely. If you have problems doing this, post back and i will help
 
well since i'm new to .net i like to see the the code with comments please.
 
Hello, this is some code I use to move forward and backwards throughs records. I running vb.net v2002 connecting to a SQL2000 database using intergrated security.

'Declare objects, use intergrated security to access Northwind db
Dim cnn1 As SqlConnection = _
New SqlConnection _
("Data Source=(local);" & "Integrated Security=SSPI;" & _
"Initial Catalog=northwind")


Dim myAdapter As SqlDataAdapter = New SqlDataAdapter( _
"SELECT * FROM customers ", cnn1)


Dim myDS As DataSet
Dim myDV As DataView
Dim myCurrencyManager As CurrencyManager
Dim relCustOrder As DataRelation


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Try

'Fill the DataSet and bind the fields...
FillDataSetAndView()

BindFields()

'Show the current record position...
ShowPosition()

Catch er As System.Exception

MsgBox("Error: " & er.Source & ": " & er.Message, _
MsgBoxStyle.Exclamation, "Unable to Connect to Customers DataTable - check SQL Network Connection")

'Write Exception message to the event log...
Dim log As EventLog = New EventLog()
log.Log = "NWind_Application"
log.Source = Me.Text
log.WriteEntry(er.ToString, EventLogEntryType.Error)
log.Close()

'Display message in StatusBar...
StatusBar1.Text = er.ToString

Finally

End Try

End Sub

Private Sub FillDataSetAndView()

'Initialize a new instance of the DataSet object...
myDS = New DataSet()

'Fill the DataSet object with data...
myAdapter.Fill(myDS, "customers")

'Set the DataView object to the DataSet object...
myDV = New DataView(myDS.Tables("Customers"))

'Set our CurrencyManager object to the DataView object...
myCurrencyManager = CType(Me.BindingContext(myDV), CurrencyManager)

End Sub

Private Sub BindFields()

'Clear any previous bindings...
txtCustomerID.DataBindings.Clear()
txtCompanyName.DataBindings.Clear()
txtContactName.DataBindings.Clear()
txtContactTitle.DataBindings.Clear()
txtAddress.DataBindings.Clear()
txtCity.DataBindings.Clear()
txtRegion.DataBindings.Clear()
txtPostalcode.DataBindings.Clear()
txtCountry.DataBindings.Clear()
txtPhone.DataBindings.Clear()
txtFax.DataBindings.Clear()

'Add new bindings to the DataView object...
txtCustomerID.DataBindings.Add("Text", myDV, "customerID")
txtCompanyName.DataBindings.Add("Text", myDV, "companyname")
txtContactName.DataBindings.Add("Text", myDV, "contactname")
txtContactTitle.DataBindings.Add("Text", myDV, "contacttitle")
txtAddress.DataBindings.Add("Text", myDV, "Address")
txtCity.DataBindings.Add("Text", myDV, "City")
txtRegion.DataBindings.Add("Text", myDV, "Region")
txtPostalcode.DataBindings.Add("Text", myDV, "Postalcode")
txtCountry.DataBindings.Add("Text", myDV, "Country")
txtPhone.DataBindings.Add("Text", myDV, "Phone")
txtFax.DataBindings.Add("Text", myDV, "Fax")


'Display a ready status...
StatusBar1.Text = "Ready"

End Sub

Private Sub ShowPosition()

'Display the current position and the number of records
txtRecordPosition.Text = myCurrencyManager.Position + 1 & _
" of " & myCurrencyManager.Count()

End Sub

Private Sub bntMoveFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntMoveFirst.Click

'Set the record position of the first record...
myCurrencyManager.Position = 0

'Show the current record position...
ShowPosition()

End Sub

Private Sub btnMovePrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMovePrevious.Click

'Move to the previous record...
myCurrencyManager.Position -= 1

'Show the current record position...
ShowPosition()

End Sub

Private Sub btnMoveNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveNext.Click

'Move to the next record...
myCurrencyManager.Position += 1

'Show the current record position...
ShowPosition()

End Sub

Private Sub btnMoveLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveLast.Click

'Set the record position to the last record...
myCurrencyManager.Position = myCurrencyManager.Count - 1

'Show the current record position...
ShowPosition()

End Sub


Is this of any help to you?? I'm sure there are other ways of doing this, but this works for me.

Cheers! wearytraveller
 
I'm still not a fan of binding data directly to the GUI.

And the whole "scroll through records" thing has always bothered me. How useful is it? Making a user go one record at a time trying to find the one they want. It's faster and most users find it preferable to be able to see a filtered list of items so they can pick the one they want based off of some key fields, rather then scroll through the data, wait for an entire page of data to load.

Once you break free from the old Access format, and get away from directly bound data, moving through data becomes much more fluid and direct for the users.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
I tend to agree with rick. select * from ... is never a good idea I mostly only get "one" record at a time. this thing would grind to a halt if you had a million records. using parameters to fill the insert, update and delete statements will render the databinding useless.

Believe me your users don't want to step thru a million records unless they work for the governement (like me).

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
thank you for your views guys(rick and chrissie1) & belive me i know exacly what you guys saying.this problem arise to me cos i'm new to .net and i want to find out how the old things are don in the new way.

i will try out your code "wearytraveller" and do remember this is asp.net and not just vb.net. threr are some things
that dosn't work in asp.net as in vb.net(from what i have experienced , eg:- msgbox don't work!)
 
Just to throw-in another comment....

Although I've tested this b/c I likewise do not like the select * from..., but doesn't SP2 prevent using select * from...?

Anyway, that's just for consideration.

Dale
 
I am sure it (SP2) doesnt block select *, this is a key part of the sql language and does have many uses, especially in rapid application development when data changes can be quite frequent.
 
hey wearytraveller the currencymanager is only for vb.net and not for asp.net. so if you know some code that work in asp.net pls post it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top