473,387 Members | 1,512 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,387 software developers and data experts.

Show records

Hi,

Als a beginner, I am looking for a way to show records
My code is
Private sub Connection(
Dim odbconn_Pro As OleDbConnectio
Dim odbcomm_Pro As OleDbComman
Dim odbdare_Pro As OleDbDataReade
Dim DataFile as Strin
DataFile = "H:\Production\Prod.mdb
odbconn_Pro = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; "
& "DATA SOURCE=" & DataFile
odbcomm_Pro = New OleDbComman
odbcomm_Pro.CommandText = "SELECT * FROM Collection ORDER BY bt_code
odbcomm_Pro.Connection = odbconn_Pr
odbcomm_Pro.Connection.Open(
odbdare_Pro = odbcomm_Pro.ExecuteReade
If odbdare_Pro.HasRows The
ShowDetail(
End I
End Su

Private Sub ShowDetail(
While odbdare_Pro.Read(
lblCode.Text = odbdare_Pro("bt_code"
lblName.Text = odbdare_Pro("bt_Name"
....
....
End Whil
End Su

When this proram run. It show only the last record. I know why, because I use : While odbdare_Pro.Read()
So the program read all the records and shows the last one
What I want is the program just shows the first record

Meanwhile I have 4 toolbar Buttons : "First Record", "Previous", "Next" and "Last" to navigate which record to show
After the first record is showed, the user can click one of the 4 buttons.
If the "First Record" button is clicked, the first record will be showed
If the "Previous" button is clicked, the previous record of the shown record will be showed
If the "Next" button is clicked, the next record of the shown record will be showed
If the "Last" button is clicked, the last record will be showed

How can I do like this ? Please somebody help me

Thanks in advance

Joachim
Nov 20 '05 #1
15 1887
Hi Joachim,

If you read using the datareader and not store that in an object you have
only the latest information in memory.

However just by using the dataadapter, the dataset (with all what is in
this), using the *data*binding and the bindinmanager you can do all you want
in a very easy way, have a look for your self to it in/on msdn.

Cor
Nov 20 '05 #2
Cor
Can you give me a sample, please

Thanks.
Nov 20 '05 #3
Hi Joachim,

I do this in this message so watch for typos
Private sub Connection()
Dim odbconn_Pro As OleDbConnection
Dim odbcomm_Pro As OleDbCommand
Dim odbdare_Pro As OleDbDataReader
Dim DataFile as String
DataFile = "H:\Production\Prod.mdb"
odbconn_Pro = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _ & "DATA SOURCE=" & DataFile)
odbcomm_Pro = New OleDbCommand
odbcomm_Pro.CommandText = "SELECT * FROM Collection ORDER BY bt_code" odbcomm_Pro.Connection = odbconn_Pro
odbcomm_Pro.Connection.Open()

dim ds as new dataset
dim da as new dataadaper(odbcomm_Pro)
da.fill(ds)
cma = CType(BindingContext(ds.Tables(0)), CurrencyManager)
textbox1.DataBindings.Add(New Binding("Text", ds.Tables(0),
"YourFieldName"))

With seting the
cma.position = 0 you set the position on the first postision and the first
row will be displayed

I hope this clears it a little bit otherwise reply

Cor
Nov 20 '05 #4
Cor, thanks for your code. But....

What is cma in :
cma = CType(BindingContext(ds.Tables(0)), CurrencyManager
textbox1.DataBindings.Add(New Binding("Text", ds.Tables(0)
"YourFieldName")

Can I do like this ?
private sub ...
..
..
da.fill(ds
ShowData(0
end su

private sub ShowData(posi
cma = CType(BindingContext(ds.Tables(posi)), CurrencyManager)
textbox1.DataBindings.Add(New Binding("Text", ds.Tables(posi)
"YourFieldName")
end su

Nov 20 '05 #5
Cor is absolutely correct here! Definitely don't use a DataReader is this
is what you need. A reader needs an open and available connection and
leaving a Reader open for the entire user session is bad news. Use a
Datatable! He posted the code but the main reason that I'm writing this is
to emphasize the difference between teh two approaches. DataReaders are
connected objects, only work when connected. DataTables/DataSets etc
aren't. They connect and close so they work independently of a database.
For this you get a little performance hit but it's manageable in most
instances and you get a lot of functionality. Confusing these two approachs
can be very problematic.

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
http://www.devbuzz.com/content/zinc_...center_pg1.asp
"Joachim" <an*******@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
Hi,

Als a beginner, I am looking for a way to show records.
My code is :
Private sub Connection()
Dim odbconn_Pro As OleDbConnection
Dim odbcomm_Pro As OleDbCommand
Dim odbdare_Pro As OleDbDataReader
Dim DataFile as String
DataFile = "H:\Production\Prod.mdb"
odbconn_Pro = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _ & "DATA SOURCE=" & DataFile)
odbcomm_Pro = New OleDbCommand
odbcomm_Pro.CommandText = "SELECT * FROM Collection ORDER BY bt_code" odbcomm_Pro.Connection = odbconn_Pro
odbcomm_Pro.Connection.Open()
odbdare_Pro = odbcomm_Pro.ExecuteReader
If odbdare_Pro.HasRows Then
ShowDetail()
End If
End Sub

Private Sub ShowDetail()
While odbdare_Pro.Read()
lblCode.Text = odbdare_Pro("bt_code")
lblName.Text = odbdare_Pro("bt_Name")
.....
.....
End While
End Sub
When this proram run. It show only the last record. I know why, because I use : While odbdare_Pro.Read() So the program read all the records and shows the last one.
What I want is the program just shows the first record.

Meanwhile I have 4 toolbar Buttons : "First Record", "Previous", "Next" and "Last" to navigate which record to show. After the first record is showed, the user can click one of the 4 buttons.
If the "First Record" button is clicked, the first record will be showed.
If the "Previous" button is clicked, the previous record of the shown record will be showed. If the "Next" button is clicked, the next record of the shown record will be showed. If the "Last" button is clicked, the last record will be showed.

How can I do like this ? Please somebody help me.

Thanks in advance.

Joachim.

Nov 20 '05 #6
Hi Joachim

I was a little bit in a hurry.
\\\
lblCode.DataBindings.Add(New Binding("Text", ds.Tables(0),
"bt_code"))
///

This binding can be done as soon as the dataset is filled (with an untyped
dataset as you have) (and it has to be done only one time)

The currencymanager is not a money manager, it keep track of the current row
in the dataset.
cma is that object
cma.position = x is the current row. You can use it in a click event by
instance in a previous button

\\\
sub click ButtonPrevious
if cma.positions > 0 then
cma.position -= 1
end if
///
You have not to fill the textboxes now or move the contents to a row,
however when you do a dataadapter update, you normaly have to add before the
update (I give it now otherwise you ask it in future)
\\\
cma.EndCurrentEdit()
///
Watch what you set global and what not, that cma you should declare global
of course.
\\
Private cma As CurrencyManager
///
I hope this shows it a little bit?

Cor

Nov 20 '05 #7
Hi, Co
Here below is my code. But I got a error in line 18
The message of the error is like this

An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dl
Additional information: This would cause two bindings in the collection to bind to the same property

Sorry Cor if I ask you too much, I am really a beginner
Please check my coe, maybe I have done something wrong

Thanks

Joachim

============================
1 Private Sub SetConnection(
2 Dim DataFile as Strin
3 DataFile = "C:\Production\Product.mdb
4 odbconn_Pro = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; "
5 & "DATA SOURCE=" & DataFile
6 odbcomm_Pro = New OleDbComman
7 odbcomm_Pro.CommandText = "SELECT * FROM Collection ORDER BY bt_code
8 odbcomm_Pro.Connection = odbconn_Pr
9 odbcomm_Pro.Connection.Open(
10 ds = New DataSe
11 da = New OleDbDataAdapter(odbcomm_Pro
12 da.Fill(ds
13 ShowDetail(
14 End Su
1
16 Private Sub ShowDetail(
17 Dim i as Intege
18 lblCode.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_code")
19 lblm1Event.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1event")
20 If Trim(lblm1Event.Text) = "" The
21 SetMatch1_Empty(False
22 Els
23 SetMatch1_Empty(True
24 lblm1Year.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1year")
25 lblm1Discipline.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1discipline")
26 i = Array.IndexOf(st_Dis, lblm1Discipline.Text
27 lblm1Discipline.Text = st_Discipline(i
28 lblm1Player1.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1player1")
29 lblm1Country1.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1country1")
30 lblm1Player2.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1player2")
31 lblm1Country2.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1country2")
32 lblm1Qualification.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1qualification")
33 i = Array.IndexOf(st_Qua, lblm1Qualification.Text
34 lblm1Qualification.Text = st_Qualification(i
35 lblm1Remark.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1remark")
36 End I
3
38 End Su

Nov 20 '05 #8
Hi Joachim,

I was expecting this error however could not write more about it because
than I would have confused you to much in my idea.

I wrote the binding has only to be set once. You can do that in a procedure
or just remove the binding everytime, however your code is in a way I make
it myself easy, can you try and tell if this works? (You can as well use
everytime me.textboxX.databinding.clear, before you do the databinding)

This is not ready, just a next step.

Cor
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll Additional information: This would cause two bindings in the collection to bind to the same property.
Private cma As CurrencyManager 1 Private Sub SetConnection()
2 Dim DataFile as String
3 DataFile = "C:\Production\Product.mdb"
4 odbconn_Pro = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _ 5 & "DATA SOURCE=" & DataFile)
6 odbcomm_Pro = New OleDbCommand
7 odbcomm_Pro.CommandText = "SELECT * FROM Collection ORDER BY bt_code" 8 odbcomm_Pro.Connection = odbconn_Pro
9 odbcomm_Pro.Connection.Open()
10 ds = New DataSet
11 da = New OleDbDataAdapter(odbcomm_Pro)
12 da.Fill(ds) DoBinding()
cma = CType(BindingContext(ds.Tables(0)), CurrencyManager) 14 End Sub


Proivate sub ShowText
cma.position = an indexer to the rows you want to show
End Sub

Private Sub DoBinding()
static binded as boolean
if binded = false then
lblCode.DataBindings.Add(New Binding("Text", ds.Tables(0),
"bt_code"))
lblm1Event.DataBindings.Add(New Binding("Text", ds.Tables(0),
"bt_m1event"))
'why you use that set event while you can everytime just test the value of
the label?
lblm1Year.DataBindings.Add(New Binding("Text", ds.Tables(0),
"bt_m1year"))
lblm1Discipline.DataBindings.Add(New Binding("Text",
ds.Tables(0), "bt_m1discipline"))
lblm1Player1.DataBindings.Add(New Binding("Text", ds.Tables(0),
"bt_m1player1"))
lblm1Country1.DataBindings.Add(New Binding("Text", ds.Tables(0),
"bt_m1country1"))
lblm1Player2.DataBindings.Add(New Binding("Text", ds.Tables(0),
"bt_m1player2"))
lblm1Country2.DataBindings.Add(New Binding("Text", ds.Tables(0),
"bt_m1country2"))
lblm1Qualification.DataBindings.Add(New Binding("Text",
ds.Tables(0), "bt_m1qualification"))
lblm1Remark.DataBindings.Add(New Binding("Text", ds.Tables(0),
"bt_m1remark"))
binded = true
End If
End Sub

Nov 20 '05 #9
Hi Cor
I have followed your code, but I got the same error message

-------------- error message -----------
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dl
Additional information: This would cause two bindings in the collection to bind to the same property
-------------------------------------------

This time in line 4. I tried to remove the 'New Binding', but the same message came out

What do you mean at line 6

1 Private Sub DoBinding(
2 static binded as boolea
3 if binded = false the
4 lblCode.DataBindings.Add(New Binding("Text", ds.Tables(0),"bt_code")
5 lblm1Event.DataBindings.Add(New Binding("Text", ds.Tables(0),"bt_m1event")
6 'why you use that set event while you can everytime just test the value of the label
7 lblm1Year.DataBindings.Add(New Binding("Text", ds.Tables(0)
Nov 20 '05 #10
Hi Cor

First of all : THANKS A LOT
Sorry, for my earlier post. I have made a mistake, that's why the error message came uit again
I checked it again and found the bug

Another question
I have 13 field in the table
Field 1 is the key
Field 2,3,4 and 5 are a group
Field 6,7,8 and 9 are a group, and als
Field 10,11,12 and 13 are a group

What I want to do is
If field 6 empty, null, " " or "", so all the fields in the same group (6, 7, 8 and 9) must not be displayed
If field 10 empty, null, " " or "", so all the fields in the same group (10, 11, 12 and 13) must not be displayed
All the fields (1 to 13) are binded, so how can I check whether field 6 and field 10

Nov 20 '05 #11
Hi Joachim,

When it is databinded it is binded. However we can prevent to show it.

That is where are the previous and next and other buttons in those you can
call a procedure which only does. (roughly written here not tested)
\\\\
dim test as string
if ds.tables(0).rows(cma.position)item(6) Not Is dbnull.value then
test = ...........(6).tostring.replace(" ","")
else
test = ""
end if
if test = "" then
me.labelwhatever.visible = valse
me...
else
me.labelwhatever.visible = true
me....
end if
if ...... for the other fields
///
I hope this gives some idea's and show you also the use of the
cma.postition

Cor
Nov 20 '05 #12
Hi Joachim show something more, where is it in the program.
And is the dataset really filled.

If you want to test that you can do something as
If ds.tables(0) not Is Nothing .....

if ds.tables(0).rows(cma.position).item(6) Not Is dbnull.value then
test = ds.tables(0).rows(cma.position).item(6).tostring.r eplace(" ","")
else
test = ""
end if

Nov 20 '05 #13
Cor, here below is the code
The message came uti form line *

Private sub SetConnection(
......
da_Badminton.Fill(ds
DoBinding(
cm_Badminton = CType(BindingContext(ds.Tables(0)), CurrencyManager
End Su

Private Sub DoBinding(
Static binded As Boolea
If binded = False The
lblCode.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_code")
lblm1Event.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1event")
lblm1Year.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1year")
lblm1Player1.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1player1")
lblm1Country1.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1country1")
lblm1Player2.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1player2")
lblm1Country2.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1country2")
lblm1Qualification.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1qualification")
lblm1Remark.DataBindings.Add(New Binding("Text", ds.Tables(0), "bt_m1remark")

** If ds.Tables(0).Rows(cm_Badminton.Position).Item(2) Not Is DBNull.Value The
Tempo = ds.Tables(0).Rows(cm_Badminton.Position).Item(2).T oString.Replace(" ", ""
els
Tempo = "
End I
If Tempo = "" the
DoSomething(
End i

Nov 20 '05 #14
Hi Joachim,

I am lucky I asked you to send the code.

See this..
DoBinding()
cm_Badminton = CType(BindingContext(ds.Tables(0)),

CurrencyManager)

In that DoBinding you use that cm_Badminton while it does not even exist.
Not only for that because you can change those rows, however for the use you
have to set that hiding routine outside that DoBinding, hiding those fields
have nothing to do with the binding.

By Instance
\\\
DoBinding()
cm_Badminton = CType(BindingContext(ds.Tables(0)), CurrencyManager)
DoHiding
////
Than you can do on your event from the button clicks as well everytime
\\\
DoHiding
///


Nov 20 '05 #15
Hi Cor

It works
Again : THANKS A LOT to you Cor
I am very appreciated

Now, I am learning the DataGrid
Maybe you can also help me when I post my question in the other thread

Best regard
Joachim.
Nov 20 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: David Ehmer | last post by:
The code below is 2 rows in a table, the top row contains a message to be shown if the recordset returns no matches. The 2nd row will display any matches. Problem is that if no matches are found...
4
by: mugen | last post by:
hi.. have a continious form. there are some records that i'd like to omit from showing in the form. is it possible to set a check box that if set to true will make sure that the record is not...
0
by: Tom Kaminski [MVP] | last post by:
I want to show a table of master records, with the right most column displayed as a comma (or space) delimited list of details. The practical application of this is a thesaurus, where the master...
8
by: PAPutzback | last post by:
How do I keep the form up.
16
by: William Buchanan | last post by:
Hi folks I want to show 2 records on a page side by side. Each record has an image which will be displayed and a bit of text. How can I do this? Thanks Will
2
by: Zeljko | last post by:
I'm creating Address book. Header of the main form (frmAddress) contains combo box (cboFilter) to filter records by Occupation on main Form(Ocupation1). That's working. Combo box also have "Show...
0
by: Reinhard | last post by:
Hi, Need some directions on Ajax, UpdatePanel and Gridview to achive the following: I like to show a Gridview with Data ONLY if the user is interested in Details, but without a full page...
1
by: ochalove26 | last post by:
hi all, i'm a new programmer... i use a combo box to filtering the records in my sub form..it was works...but when i want to show all records in my sub form it doesnt works..how it would be?please...
6
by: robin1983 | last post by:
HI, i have large code to show the data access from a table. Actually i want to show 10 records at a time in one pages and remaining records in the othere pages. as for example I have a table...
2
by: banderson | last post by:
Hello, I have a data entry form for a table with information about buildings and am having a problem making a combo box do what I want. I would like to make the combo box show a list of unique bldg...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.