473,320 Members | 2,110 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,320 software developers and data experts.

Retrieve data from a db (Question)


Hi,
I have a form where I need to display the data of a department that
stores in a access db.

When I first load the form it will call a function name loaddata which
will get the first record from the db and then display for the user:

oleDbConnection1.Open();
OleDbDataReader objReader = objdisplay.ExecuteReader(); --> this will
select DEPT_CODE,DEPT_NAME,DEPT_ATTN FROM DEP_TABLE

if (objReader.HasRows)
{
objReader.Read();
textBox1.Text = Convert.ToString(objReader["DEPT_CODE"]);
textBox2.Text = Convert.ToString(objReader["DEPT_NAME"]);
textBox3.Text = Convert.ToString(objReader["DEPT_ATTN"]);

(...)

Then I have various button, one of them is NEXT, which I want to read
the next record from the db. I'm new in C# and in VB, I will use the
MoveNext to move to the next record, but is it the same in C#?

Can someone help me?

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
4 3908
Hi Claudia,

Call OleDbDataReader.Read() again for each time you want to read the next record from the query.
However, this will keep the database connection open for a 'long' time and you might want to store the result in a local DataSet/DataTable. Using OleDbDataReader.Read won't allow you to go back to a previous record either.

You can use the OleDbDataAdapter class to fill a dataset from a query to the database.

On Sat, 21 May 2005 05:38:35 +0200, Claudia Fong <cd********@yahoo.co.uk> wrote:

Hi,
I have a form where I need to display the data of a department that
stores in a access db.

When I first load the form it will call a function name loaddata which
will get the first record from the db and then display for the user:

oleDbConnection1.Open();
OleDbDataReader objReader = objdisplay.ExecuteReader(); --> this will
select DEPT_CODE,DEPT_NAME,DEPT_ATTN FROM DEP_TABLE

if (objReader.HasRows)
{
objReader.Read();
textBox1.Text = Convert.ToString(objReader["DEPT_CODE"]);
textBox2.Text = Convert.ToString(objReader["DEPT_NAME"]);
textBox3.Text = Convert.ToString(objReader["DEPT_ATTN"]);

(...)

Then I have various button, one of them is NEXT, which I want to read
the next record from the db. I'm new in C# and in VB, I will use the
MoveNext to move to the next record, but is it the same in C#?

Can someone help me?

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #2

Thanks!

If I use the DataAdapter, I can call it again for example to retrieve
data from the previous record? Because I have 3 more buttons, TOP (so
the user can move to the top of the table), Bottom(move to the bottom of
the table), Next(move to the next record) and Previous (move to the
previous record).

Do you have an example of how to use the DataAdapter?

I just started learning C#...
Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3
Claudia,

A DataReader is fine for forward-only access, in fact it's the fastest way
to do that. But if you want to navigate you'll need to use a DataAdapter.

Google on "data application block" -- that should take you to some good
downloadable samples at Microsoft's site. A similar search on "DataAdapter
example" or "DataAdapter tutorial" will probably turn up zillions of other
examples.

--Bob

"Claudia Fong" <cd********@yahoo.co.uk> wrote in message
news:e1*************@TK2MSFTNGP12.phx.gbl...

Thanks!

If I use the DataAdapter, I can call it again for example to retrieve
data from the previous record? Because I have 3 more buttons, TOP (so
the user can move to the top of the table), Bottom(move to the bottom of
the table), Next(move to the next record) and Previous (move to the
previous record).

Do you have an example of how to use the DataAdapter?

I just started learning C#...
Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #4
With a DataAdapter the idea is to connect to the database once, retrieve all data and store it in a local DataSet. There will be no need to call it again to retrieve previous records as all the records will be stored in the DataSet (in a DataTable).

If you make changes to the DataTable, add new rows, delete or change rows, you can use the DataAdapter to post back all changes to the database when you are done doing changes, or when you see fit.

In addition to Bob's search phrases you can search for 'dataAdapter1.Fill' and/or 'dataAdapter1.Update'

On Mon, 23 May 2005 03:25:14 +0200, Claudia Fong <cd********@yahoo.co.uk> wrote:

Thanks!

If I use the DataAdapter, I can call it again for example to retrieve
data from the previous record? Because I have 3 more buttons, TOP (so
the user can move to the top of the table), Bottom(move to the bottom of
the table), Next(move to the next record) and Previous (move to the
previous record).

Do you have an example of how to use the DataAdapter?

I just started learning C#...
Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #5

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

Similar topics

5
by: David Rasmussen | last post by:
Some sites seem to be session driven in the sense that if I visit the homepage and do a few clicks I can navigate anywhere I want, but if I paste the current location into a new browser window...
2
by: forums_mp | last post by:
I've got an STL class (see below) with two functions to store and retrieve data - msg structs. The "Store" function when called will copy the received message (depending on which message) into...
2
by: crocketo | last post by:
Hi, I've made a winform with several labels, textboxes and a datagrid. My question is: How do I, when a row in the datagrid is clicked, retrieve that data? Let's say I've got a datagrid with...
3
by: James Geurts | last post by:
This is probably more of an ASP.Net situation rather than c#, but since all of my code behind is in c#, maybe it fits here. I'm wondering, generally, at what point is it too inefficient to store...
3
by: Asus | last post by:
Hello, I'm new to Web Services. I'm trying to develop a Web Service that retrieves some data out of a database and sends them to the client as a DataSet when a method is invoked. My question...
6
by: lovecreatesbeauty | last post by:
/* It seems that when an int with width of four bytes is assigned to a one byte width char, the first three bytes from left to right are discarded and the rightest byte is assigned to that char....
1
by: jpabich | last post by:
I am trying to retrieve an Oracle Time stamp with time zone information. Somewhere between Oracle and .NET, it is dropping this data. Can you tell me how to retrieve it?
13
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end...
3
crystal2005
by: crystal2005 | last post by:
Hi all, As the title, how do i retrieve a value from the URL format string after i pass it to the other page. E.g. example in my case is Say in admin.aspx i have a link to questions.aspx. I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.