problem in displayin records on a form

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

Join Date: Jun 2007
Posts: 82
Reputation: preetham.saroja is an unknown quantity at this point 
Solved Threads: 1
preetham.saroja's Avatar
preetham.saroja preetham.saroja is offline Offline
Junior Poster in Training

problem in displayin records on a form

 
0
  #1
Jun 20th, 2007
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...
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 437
Reputation: Fungus1487 is on a distinguished road 
Solved Threads: 50
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Pro in Training

Re: problem in displayin records on a form

 
0
  #2
Jun 20th, 2007
this code is under next button click ?

have you checked what is stored in maxrws ?

what integer value does it contain ?
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 121
Reputation: manal is an unknown quantity at this point 
Solved Threads: 17
manal's Avatar
manal manal is offline Offline
Junior Poster

Re: problem in displayin records on a form

 
0
  #3
Jun 21st, 2007
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
  1. Public next_record As Integer
Double click Next Record button to access the code and write this
  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
"give only what u willing to receive "
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 82
Reputation: preetham.saroja is an unknown quantity at this point 
Solved Threads: 1
preetham.saroja's Avatar
preetham.saroja preetham.saroja is offline Offline
Junior Poster in Training

Re: problem in displayin records on a form

 
0
  #4
Jun 21st, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 121
Reputation: manal is an unknown quantity at this point 
Solved Threads: 17
manal's Avatar
manal manal is offline Offline
Junior Poster

Re: problem in displayin records on a form

 
0
  #5
Jun 21st, 2007
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 ,
"give only what u willing to receive "
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 437
Reputation: Fungus1487 is on a distinguished road 
Solved Threads: 50
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Pro in Training

Re: problem in displayin records on a form

 
0
  #6
Jun 21st, 2007
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
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 82
Reputation: preetham.saroja is an unknown quantity at this point 
Solved Threads: 1
preetham.saroja's Avatar
preetham.saroja preetham.saroja is offline Offline
Junior Poster in Training

Re: problem in displayin records on a form

 
0
  #7
Jun 26th, 2007
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..
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC