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

mysqldatareader.read()

mysqldatareader.read()
is it capable of returning multiple rows in the database or does it return only the first row that matches the criteria?
if so, then how do I read multiple rows from the table.
also, does checking if the function returned true or false say anything about empty sets?
Sep 9 '07 #1
5 28663
Atli
5,058 Expert 4TB
Hi.

What programming language are you using?
Sep 9 '07 #2
i am using c#.......
Sep 9 '07 #3
Atli
5,058 Expert 4TB
It should be able to return multiple rows... for example:
Expand|Select|Wrap|Line Numbers
  1. // Create connection and command
  2. SqlConnection connection = new SqlConnection("Your connection string here");
  3. SqlCommand command = connection.CreateCommand();
  4. command.CommandText = "SELECT tblID FROM tbl";
  5.  
  6. // Execute command and read all rows
  7. SqlDataReader reader = command.ExecuteReader();
  8. int rowNum = 1;
  9. while (reader.Read())
  10. {
  11.   Console.WriteLine("Row {0}: {1}", rowNum, reader["tblID"]);
  12.   rowNum++;
  13. }
  14.  
  15. // Close
  16. reader.Close();
  17. connection.Close();
  18.  
I imagine the same is true for MysqlDataReader
Sep 9 '07 #4
thats exactly what i am looking for, but can you show me the result in vb.net?

thank you for this post!
Nov 6 '07 #5
Atli
5,058 Expert 4TB
Hi Liquid. Welcome to TSDN!

C# and VB.NET are pretty much the same, although the syntax is a little different. I'm not that good with VB.NET so this may not be entirely correct, but I think it's pretty close.
Expand|Select|Wrap|Line Numbers
  1. ' Create connection and command
  2. Dim connection As New SqlConnection("Your connection string here")
  3. Dim command As SqlCommand = connection.CreateCommand()
  4. command.CommandText = "SELECT tblID FROM tbl"
  5.  
  6. ' Execute command and read all rows
  7. Dim reader As SqlDataReader = command.ExecuteReader()
  8. Dim rowNum As Integer = 1
  9. While (reader.Read())
  10.     Console.WriteLine("Row {0}: {1}", rowNum, reader("tblID"))
  11.     rowNum = rowNum + 1
  12. End While
  13.  
  14. ' Close
  15. reader.Close()
  16. connection.Close()
  17.  
Note that this code is using the SqlConnection objects, so it will not be able to connect to MySQL, but the MySqlConnection objects should work pretty much the same.
Nov 7 '07 #6

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

Similar topics

2
by: Gunnar | last post by:
Hello, I've just written a CPP program that reads integers from a binary file, and used this code while (my_ifstram.read( (char* ) &number, sizeof(int)) { // do something with number } My...
11
by: Markus Breuer | last post by:
I have a question about oracle commit and transactions. Following scenario: Process A performs a single sql-INSERT into a table and commits the transaction. Then he informs process B (ipc) to...
12
by: Steven T. Hatton | last post by:
I know of a least one person who believes std::ifstream::read() and std::ofstream::write() are "mistakes". They seem to do the job I want done. What's wrong with them. This is the code I...
2
by: Sandman | last post by:
Just looking for suggestion on how to do this in my Web application. The goal is to keep track of what a user has and hasn't read and present him or her with new material I am currently doing...
6
by: BBM | last post by:
I have an object that has a fairly complex construction sequence, so I have written a dedicated "factory" class that invokes the constructor of my object class (which does nothing but instantiate...
1
by: Jose Reckoner | last post by:
I'm running python 2.3 on Windows XP. Anyone have a quick small script to convert .DT1 and .DEM data to ASCII or some other format? I don't need a viewer. Thanks!
0
by: phplasma | last post by:
Hey, I am currently attempting to implement a multi-threaded C# socket, using SSL (.pem file/certification/private key combo) server using Visual Studio C# Express. I have successfully made...
1
by: jinxy | last post by:
Hello, this is my code in visual c#: namespace im_client { public partial class Form2 : Form { MySqlConnection conDatabase = new MySqlConnection("Data Source=86.123.220.28;" +...
1
by: mbewers1 | last post by:
Hi, I'm getting the following error when executing the SQL within this line of code. Originally, I had coded a stored procedure within the code but this brought up the same error. I've looked...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.