Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 21st, 2007, 03:05 AM
Registered User
 
Join Date: Mar 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default to display the records using vb.net

I am new to vb.net and trying to display the records in a sequential manner from sqlserver, but only the last record is displayed. in vb we were using rs.movenext and its not there in this. how to go about ????

While dr.Read
            TextBox1.Text = dr(0).ToString()
            TextBox2.Text = dr(1).ToString()
End While

 
Old March 21st, 2007, 03:13 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

In ADO.NET, the Read method takes care of EOF and MoveNext at the same time. So, your code probably works as expected when it comes to the database. However, look at this:

  TextBox1.Text = dr(0).ToString()

You're overwriting the Text on each iteration. Try this instead:

  TextBox1.Text += dr(0).ToString()

This adds the data for each record to the current Text.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old March 21st, 2007, 03:49 AM
Registered User
 
Join Date: Mar 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

Now my records concatenated in the textboxes. i have 4 records in my database, except the first record all the other records are displayed together!!!!!!!!:(
suppose my records like this
       name rollno
         a 10
         b 20
         c 30
         d 40

now after using as what you told

While dr.Read()

            TextBox1.Text += dr(0).ToString()

            TextBox2.Text += dr(1).ToString()
End While

it is like

textbox1 bcd
textbox2 10203040

I want to display one record at a time......how is it possible???

 
Old March 21st, 2007, 03:57 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

What do you mean with "one record at a time"? By a user's click? Or in separate lines / controls?

In what environment is this? Windows Forms / Web Forms?

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old March 21st, 2007, 04:36 AM
Registered User
 
Join Date: Mar 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is Windows Form. I want to display similar results that we display using rs.Movenext in vb, one record at a time!!!!!!i.e

i have a command button "next" when i click that only the first record

textbox1 = a
textbox2 = 10

when i click the next button again it should disply the next set of records etc......
 
Old March 21st, 2007, 05:06 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

MoveNext doesn't do anything UI related; all it does is move the Recordset to the next record. You'll need to bind your data to a UI control somehow to display it on screen.

Search Google for

"windows forms" database databind

to get some starter articles.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old March 21st, 2007, 10:12 AM
Registered User
 
Join Date: Mar 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi ,

Thanks a lot Imar :)!!!!!!! its now working.I was not aware of databinding concept and now wow its interesting to know new concepts!!!!!!!






Similar Threads
Thread Thread Starter Forum Replies Last Post
display messagebox in ASP.Net with VB.Net suresh_accudocs ASP.NET 1.0 and 1.1 Basics 7 November 5th, 2014 06:31 PM
how to print the records in vb.net curiaquita VB.NET 0 May 16th, 2008 09:49 AM
Display records in a table unmeshraut VB How-To 1 September 21st, 2007 12:04 PM
Way to display access records using asp.net method ASP.NET 1.0 and 1.1 Basics 4 April 25th, 2005 10:41 AM
Horizontal Records display doosti Classic ASP Databases 6 November 15th, 2004 01:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.