Solved

how do I loop through a odbc recordset

Posted on 2009-05-12
2
541 Views
Last Modified: 2013-12-17
I am a beginner in c# and would like to know how to loop through records in a db. It could be a recordset, etc. I need to be able to loop through items in a db table and update a filed in that row.
OdbcConnection con1 = new OdbcConnection(ConnStr);
 
            OdbcCommand cmd1 = new OdbcCommand("SELECT * from testupdate", con8);
            con1.Open();
            cmd1.ExecuteNonQuery();
            con1.Close();

Open in new window

0
Comment
Question by:bschave2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
GuitarRich earned 500 total points
ID: 24364999
Use a datareader
OdbcConnection con1 = new OdbcConnection(ConnStr);
 
            OdbcCommand cmd1 = new OdbcCommand("SELECT * from testupdate", con8);
            con1.Open();
            OdbcDataReader dr = cmd1.ExecuteReader()
            
            // To loop through
            while (dr.Read())
            {
                // deal with the data here
            }
            dr.Close();
            con1.Close();

Open in new window

0
 

Author Comment

by:bschave2
ID: 24365287
thanks for the help.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question