473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to display records one after another in a textboxes...

can anyone help in gettin the records one after another from database on a form using vb.net(sql server)..but the below code displays only first record in the textboxes...
---------------------------------------
Expand|Select|Wrap|Line Numbers
  1. private sub next_btn.click(byval,e)
  2. Dim str As String = "select * from table1"
  3.         'try to write "select distinct * from table1"
  4.         Dim con As String = ConfigurationSettings.AppSettings("preeconn")
  5.         Dim cmd As New SqlCommand(str, New SqlConnection(con))
  6.         cmd.Connection.Open()
  7.         Dim da As New SqlDataAdapter(str, con)
  8.         Dim ds As New DataSet
  9.         da.Fill(ds, "table1")
  10.         Dim maxrws As Integer
  11.         Dim i As Integer
  12.         maxrws = ds.Tables("table1").Rows.Count  'used to get the count of number of rows in a table
  13.         i = 0
  14.  
  15.         For i = 0 To maxrws - 1
  16.             id_txt.Text = ds.Tables("table1").Rows(i).Item("ID").ToString()
  17.             name_txt.Text = ds.Tables("table1").Rows(i).Item("Name").ToString()
  18.             age_txt.Text = ds.Tables("table1").Rows(i).Item("Age").ToString()
  19.             sex_txt.Text = ds.Tables("table1").Rows(i).Item("Sex").ToString()
  20.             area_txt.Text = ds.Tables("table1").Rows(i).Item("Area").ToString()
  21.         Next i
  22.         'id_txt.Text = ds.Tables("table1").Rows.Add
  23.         'id_txt.Text = ds.Tables("table1").Rows(i).Item("ID").ToString()
  24.         name_txt.Text = ds.Tables("table1").Rows(i).Item("Name").ToString()
  25.         age_txt.Text = ds.Tables("table1").Rows(i).Item("Age").ToString()
  26.         sex_txt.Text = ds.Tables("table1").Rows(i).Item("Sex").ToString()
  27.         area_txt.Text = ds.Tables("table1").Rows(i).Item("Area").ToString()
Jun 20 '07 #1
6 1734
gomzi
304 100+
can anyone help in gettin the records one after another from database on a form using vb.net(sql server)..but the below code displays only first record in the textboxes...
---------------------------------------
private sub next_btn.click(byval,e)
Dim str As String = "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
'id_txt.Text = ds.Tables("table1").Rows.Add
'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( )
Didn't have a deep look at the code, but i guess its because of you using = and not &= or +=.
You will have to append the text to the one already in the textbox to get the result that you expect.
If that aint the solution let me know, and i will look properly.

Regards,
Gomzi.
Jun 20 '07 #2
Frinavale
9,735 Expert Mod 8TB
can anyone help in gettin the records one after another from database on a form using vb.net(sql server)..but the below code displays only first record in the textboxes...
I suggest you use a StringBuilder to build a string with all the records in it for you (StringBuilder.Append(record))...and then set the TextBox.Text = StringBuilder.ToString.


-Frinny
Jun 20 '07 #3
Didn't have a deep look at the code, but i guess its because of you using = and not &= or +=.
You will have to append the text to the one already in the textbox to get the result that you expect.
If that aint the solution let me know, and i will look properly.

Regards,
Gomzi.
sir,thank u..
both of u for the quick reply-but,im not gettin the solution.&= or += doesnt works out..i even tried with while loop in place of forloop& also tried to declare" i" as global variable.but all of that went in vain,,,
plz help m out asap.....
Jun 21 '07 #4
gomzi
304 100+
can anyone help in gettin the records one after another from database on a form using vb.net(sql server)..but the below code displays only first record in the textboxes...
---------------------------------------
Hi Preethamsaroja. Your code from the for loop part doesn't make sense.
Here's what your code does,
loops from 0 to max-1 assigning the values from the dataset to the textboxes.
But, everytime, you write to the same textbox, and so your data in the textbox is going to get overwritten.
Also, once the loop gets executed, you store again some data in the textbox.
So, in short, everytime it gets overwritten and you end up with one record(the last one here) in the textbox.
Jun 21 '07 #5
sir,
so,sir could u plz tell m-what i have to do(inspite,i declared variable as global& also im using if loop(everytime)).the code is not working .could u plz tell m what i have to do......
thank u..,.,
Jun 26 '07 #6
gomzi
304 100+
sir,
so,sir could u plz tell m-what i have to do(inspite,i declared variable as global& also im using if loop(everytime)).the code is not working .could u plz tell m what i have to do......
thank u..,.,

Ya. no probs. but, can you first tell as to what exactly you want?

i.e. whether you want to display a record from the database in a form and display consecutive ones when the user presses a button

OR

you want to collect all the records from the database and append them to one another and display them in a form

My guess is that you are trying to achieve the second one. Kindly clarify.

Anyway....thought will append this.......

If you wanna achieve the second one,
Just make these changes and see.

Expand|Select|Wrap|Line Numbers
  1. dim id as string =""
  2. dim name as string =""
  3. dim age as string =""
  4. dim sex as string =""
  5. dim area as string =""
  6.  
(Frinny suggested that you go for stringbuilder...Got the above idea from that)
Expand|Select|Wrap|Line Numbers
  1. For i = 0 To maxrws - 1
  2.  
  3.   id &= ds.Tables("table1").Rows(i).Item("ID").ToString()
  4.  
  5.   name &= ds.Tables("table1").Rows(i).Item("Name").ToString()
  6.  
  7.   age&= ds.Tables("table1").Rows(i).Item("Age").ToString()
  8.  
  9.   sex&= ds.Tables("table1").Rows(i).Item("Sex").ToString()
  10.  
  11.   area &= ds.Tables("table1").Rows(i).Item("Area").ToString()
  12.  
  13. Next i
  14.  
  15. id_txt.Text = id
  16. name_txt.Text = name
  17. age_txt.Text = age
  18. sex_txt.Text = sex
  19. area_txt.Text = area
  20.  
Forget the code after the for loop. It ain't necessary in my opinion.
Jun 26 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

28
by: Lee Rouse | last post by:
Hello all, This is going to be a rather lengthy "question". I have an Access 2k database, separated front end/back end. Front end copies are on about 30 workstations and used frequently during...
3
by: Richard Hollenbeck | last post by:
I have the following query in my form's code: Private Function Get_Data(fieldNum As Integer) Dim strSQL As String Dim db As DAO.Database Dim rs As DAO.Recordset strSQL = "SELECT & "", "" & ...
12
by: jaYPee | last post by:
I have currently using a dataset to access my data from sql server 2000. The dataset contains 3 tables that is related to each other. parent/child/grandchild relationship. My problem is it's very...
1
by: David | last post by:
Hi, I have a continuous form. For each record I have a field 'HeldDate' (Text Field from a table) Against each record I have a button which sets the visibility of this text box to 'True' and...
2
by: Mikus Sleiners | last post by:
I have a control - textBox1 that is binded to objects propery - "Currency" and another control - textBox2 (read only) that is also binded to same propery. Now, i have a situation where textbox1...
2
by: rn5a | last post by:
This function in a VB class file takes UserID as a parameter & returns a SqlDataReader to the calling function which exists in a ASPX page: Namespace NConnect Public Class Cart Private sqlConn...
2
by: rn5a | last post by:
The different Validation controls like RequiredFieldValidator, RangeValidator etc. have a property named Display. This property can have 3 values - Dynamic, Static & None. What's the difference...
10
by: webgirl | last post by:
Hi there, I've been searching the net & the forums here over the last few days for help with my problem & am getting myself really confused.. hoping someone may be able to help me here. I've...
2
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.