944,030 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1596
  • VB.NET RSS
Jun 20th, 2007
0

problem in displayin records on a form

Expand Post »
Dim str AsString = "select * from table1"
'try to write "select distinct * from table1"
Dim con As String = ConfigurationSettings.AppSettings("preeconn")
Dim cmd As New SqlCommand(str, New SqlConnection(con))
cmd.Connection.Open()
Dim da As New SqlDataAdapter(str, con)
Dim ds As New DataSet
da.Fill(ds, "table1")
Dim maxrws As Integer
Dim i As Integer
maxrws = ds.Tables("table1").Rows.Count 'used to get the count of number of rows in a table
i = 0
For i = 0 To maxrws - 1
id_txt.Text = ds.Tables("table1").Rows(i).Item("ID").ToString()
name_txt.Text = ds.Tables("table1").Rows(i).Item("Name").ToString()
age_txt.Text = ds.Tables("table1").Rows(i).Item("Age").ToString()
sex_txt.Text = ds.Tables("table1").Rows(i).Item("Sex").ToString()
area_txt.Text = ds.Tables("table1").Rows(i).Item("Area").ToString()
Next i
name_txt.Text = ds.Tables("table1").Rows(i).Item("Name").ToString()
age_txt.Text = ds.Tables("table1").Rows(i).Item("Age").ToString()
sex_txt.Text = ds.Tables("table1").Rows(i).Item("Sex").ToString()
area_txt.Text = ds.Tables("table1").Rows(i).Item("Area").ToString()
----------------this is codin under next_button click.but at the moment its displayin only first record from the database on the form..plz tell m whats the problem...
Similar Threads
Reputation Points: 5
Solved Threads: 1
Junior Poster in Training
preetham.saroja is offline Offline
82 posts
since Jun 2007
Jun 20th, 2007
0

Re: problem in displayin records on a form

this code is under next button click ?

have you checked what is stored in maxrws ?

what integer value does it contain ?
Reputation Points: 66
Solved Threads: 56
Posting Pro in Training
Fungus1487 is offline Offline
459 posts
since Apr 2007
Jun 21st, 2007
0

Re: problem in displayin records on a form

Ok
Your code won't display the next record , it will always display the same record over and over , any way I think it’s the last one in table not the first.
The problem is u not keep track of which the next record is ! the for loop here dose NOT do that too.
To solve this, first define global variable
VB.NET Syntax (Toggle Plain Text)
  1. Public next_record As Integer
Double click Next Record button to access the code and write this
VB.NET Syntax (Toggle Plain Text)
  1. If next_record <= maxrws - 1 Then
  2. id_txt.Text = ds.Tables("table1").Rows(i).Item("ID").ToString()
  3. name_txt.Text = ds.Tables("table1").Rows(i).Item("Name").ToString()
  4. age_txt.Text = ds.Tables("table1").Rows(i).Item("Age").ToString()
  5. sex_txt.Text = ds.Tables("table1").Rows(i).Item("Sex").ToString()
  6. area_txt.Text = ds.Tables("table1").Rows(i).Item("Area").ToString()
  7. next_record = next_record + 1 ' here we keep track of which the Next record is
  8. Else
  9. ………………… ' write what u want to do when it reach the last record , maybe to start all over again or anything
  10.  
  11.  
  12. End If
Good luck
Reputation Points: 37
Solved Threads: 17
Junior Poster
manal is offline Offline
122 posts
since Mar 2006
Jun 21st, 2007
0

Re: problem in displayin records on a form

thanks for the quick reply for both of u,
but i dont c any changes-inspite i declare it has global variables& else if i use while-loop instead of if-loop...(And also it returns maxrws=26)
plz helpmm
Reputation Points: 5
Solved Threads: 1
Junior Poster in Training
preetham.saroja is offline Offline
82 posts
since Jun 2007
Jun 21st, 2007
0

Re: problem in displayin records on a form

Quote ...
but i dont c any changes-inspite i declare it has global variables & else if i use while-loop instead of if-loop And also it returns maxrws=26)
plz helpmm
first of all if is NOT loop u use it to test condition and i do not know why u using the for or while loop !
in ur code each time u press next button what will happen is
1/ make connection to database
2/get number of raws in table
3/goes through ALL the record but u actually display the same one each time .

but when u define global varaible , each time user press next button it will incremnt by one so u keep track of the next record . and NO need for for loop .

i hope its clear now ,
Reputation Points: 37
Solved Threads: 17
Junior Poster
manal is offline Offline
122 posts
since Mar 2006
Jun 21st, 2007
0

Re: problem in displayin records on a form

easiest way is to store your data in a multidimensional array on the page load.

then when a user presses a button i.e. next record just increment the array value. the same idea is used for getting values from a database for every request.

you need some way of storing where you are at in the list of records that are returned from the db. And you wont want to loop through with a for loop everytime. if u change that for loop to add the data to an array then use the array youll find its alot easier
Reputation Points: 66
Solved Threads: 56
Posting Pro in Training
Fungus1487 is offline Offline
459 posts
since Apr 2007
Jun 26th, 2007
0

Re: problem in displayin records on a form

yes,sir
I understood what u said,but inspite i declare global variable&also i dont use loops-im n2 able to access the records--
can u plz give m details to how to write the code...
thanks..
Reputation Points: 5
Solved Threads: 1
Junior Poster in Training
preetham.saroja is offline Offline
82 posts
since Jun 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: Test Script
Next Thread in VB.NET Forum Timeline: help help ehlp help plehp with (xml)





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


Follow us on Twitter


© 2011 DaniWeb® LLC