| | |
problem in displayin records on a form
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
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...
'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...
this code is under next button click ?
have you checked what is stored in maxrws ?
what integer value does it contain ?
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
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
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
Double click Next Record button to access the code and write this
Good luck
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)
Public next_record As Integer
VB.NET Syntax (Toggle Plain Text)
If next_record <= maxrws - 1 Then 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_record = next_record + 1 ' here we keep track of which the Next record is Else ………………… ' write what u want to do when it reach the last record , maybe to start all over again or anything End If
"give only what u willing to receive "
•
•
•
•
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
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 "
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
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
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
![]() |
Similar Threads
- Problem with my code. (VB.NET)
- problem in sending mail form web application (ASP.NET)
- how to load an image to a form (Visual Basic 4 / 5 / 6)
Other Threads in the VB.NET Forum
- Previous Thread: Test Script
- Next Thread: help help ehlp help plehp with (xml)
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add advanced application array assignment basic binary box button buttons center click code combo connectionstring convert cpu data database databasesearch datagrid datagridview design designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net number opacity pan peertopeervideostreaming picturebox picturebox2 port print printpreview record regex reports" reuse right-to-left save savedialog search serial socket sorting sqldatbase sqlserver storedprocedure string temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet vista visual visualbasic visualbasic.net visualstudio.net web wpf xml





