|
-
Mar 28th, 2008, 07:43 AM
#1
Thread Starter
Lively Member
more then one record
I am trying to retrieve ten fields each from a different column in access 2007 and put them in vb.net labels. I can always mange to get the last record in the table but how can I get 10 records each from different columns?
Code:
Dim objconnection As New OleDbConnection(connection)
objconnection.Open()
Dim Sql As String = "select * From aa Where bb = 98"
Dim objCommand As New OleDbCommand(Sql, objconnection)
Dim objReader As OleDbDataReader
objReader = objCommand.ExecuteReader
If objReader.HasRows Then
While objReader.Read
Label11.Text = (objReader.GetString(1))
End While
End If
Thats my code for retrieving one record how can i change it to retrieve ten?
Thankss
-
Mar 28th, 2008, 07:46 AM
#2
Re: more then one record
Do you mean ten records (read fires ten times) of ten fields from one record (read fires once).
vb.net Code:
If objReader.HasRows Then
While objReader.Read
Label11.Text = (objReader.GetString(1))
Label12.Text = (objReader.GetString(2))
Label13.Text = (objReader.GetString(3))
.....
End While
End If
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Mar 28th, 2008, 07:49 AM
#3
Thread Starter
Lively Member
Re: more then one record
No No sorry if i wasnt clear i ment i have ten diffrent reecord in one table where bb in 98. I want all ten record deisplayed in ten diffrent label boxes.
By changing objreader.getsting(1)) to objreader.getsting(2)), it retrives the same record but instead of getting the first field it gets the secound field. I do not want that i want the other ten records. Thanks
-
Mar 28th, 2008, 07:56 AM
#4
Re: more then one record
Try like this:
vb.net Code:
Dim x as Integer = 11
Dim obj as Window.Forms.Lable
Dim strLName as String = String.Empty
If objReader.HasRows Then
While objReader.Read
strLName = "Lable" & x.ToString()
obj = strName
directcast(obj,Windows.Forms.Lable).Text = (objReader.GetString(1))
End While
End If
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Mar 28th, 2008, 08:33 AM
#5
Thread Starter
Lively Member
Re: more then one record
Sorry Gary could you explain to how this work? So that i understand it and not just copy it. Thanks
-
Mar 28th, 2008, 08:54 AM
#6
Thread Starter
Lively Member
Re: more then one record
Also where u have written
obj = strName
what does strName represent?
-
Mar 28th, 2008, 09:58 AM
#7
Re: more then one record
You need to increment the the lable name. This can be done in various ways. You can have a counter and code the counter to increment and use that number to decide which hard coded label you need to write to. Or you use the contatinated string (Lable + incremtent) to generate a name use the name to set the object on the form to that label and a directcast to set the object to a label and place the text there
Sometimes the Programmer
Sometimes the DBA
Mazz1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|