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

Reader problem...

Newbie alert!

I am trying to get data from my mySQL database...

With some help, I have got this far, but there is an exception in data.dll
(??) on the :

"OleDbDataReader Reader = Command.ExecuteReader();"

line.

Can you see a problem here ?
string ConnectionString = "Location=myconn;Provider='MySqlProv.3.0';User
ID=*******;Integrated Security=;Data Source=******;Extended
Properties=;Password=********";

OleDbConnection Connection = new OleDbConnection(ConnectionString);

OleDbCommand Command = new OleDbCommand("Select id from users where
surname='Lister' ad firstname='Craig'", Connection);

Connection.Open();

OleDbDataReader Reader = Command.ExecuteReader();

// while(Reader.Read())

{

textBox1.Text = Reader["id"].ToString();

}
--
Websites:
http://www.thelisters.co.uk/
http://www.myschoolmates.com/

MSN Messenger: cr***********@hotmail.com
Nov 17 '05 #1
3 1502
Hey Craig,

First check the connection (Is there any exception executing the command?).
textBox1.Text = Reader["id"].ToString(); Second, use this instead:
textBox1.Text = Reader.GetInt32(Reader.GetOrdinal("ID"));

Third, which exception are you getting?

Fourth, I think mySQL requires ODBC. worth to check...

-Moty-
"Craig Lister" <in********@removethelisters.co.uk> wrote in message
news:42***********************@news.zen.co.uk... Newbie alert!

I am trying to get data from my mySQL database...

With some help, I have got this far, but there is an exception in data.dll
(??) on the :

"OleDbDataReader Reader = Command.ExecuteReader();"

line.

Can you see a problem here ?
string ConnectionString = "Location=myconn;Provider='MySqlProv.3.0';User
ID=*******;Integrated Security=;Data Source=******;Extended
Properties=;Password=********";

OleDbConnection Connection = new OleDbConnection(ConnectionString);

OleDbCommand Command = new OleDbCommand("Select id from users where
surname='Lister' ad firstname='Craig'", Connection);

Connection.Open();

OleDbDataReader Reader = Command.ExecuteReader();

// while(Reader.Read())

{

textBox1.Text = Reader["id"].ToString();

}
--
Websites:
http://www.thelisters.co.uk/
http://www.myschoolmates.com/

MSN Messenger: cr***********@hotmail.com

Nov 17 '05 #2

Hi Craig,

If you are developing on a Windows box:
Try these steps: create an ODBC link (system/user DSN) to your databas
in your computer's "Data sources" interfac
(Start...Programs...Administrat....etc).
Then test the connection and copy the connection string out of th
created
DSN and into your connection string in your code.

Give me a shout if that doesnt help. Just remember that on MySQL you
user has to have access to the localhost or your machine name needs t
be listed under your username in the MySQL database.

Enjoy old chap!
Fuzzymelo

--
fuzzymelo
-----------------------------------------------------------------------
fuzzymelon's Profile: http://www.msusenet.com/member.php?userid=245
View this thread: http://www.msusenet.com/t-187055242

Nov 17 '05 #3
Hiya Fuzzy!

Thanks for that...

I hold up my hands, as the code was infact right... I had a basic error in
the SQL! Apologies!

Here is the final code, which does infact return an ID, as expected.
string ConnectionString = "blah";

OleDbConnection Connection = new OleDbConnection(ConnectionString);

OleDbCommand Command = new OleDbCommand("Select id from users where
username='craig'", Connection);

Connection.Open();

OleDbDataReader Reader = Command.ExecuteReader();

Reader.Read();

// while(Reader.Read())

{

textBox1.Text = Reader["id"].ToString();

}

Now to build on to this very very basic start! Thanks for you help though!
Nice to have a few guys around who are willing to take the time and help
others!

Thanks!

"fuzzymelon" <fu***************@no-mx.msusenet.com> wrote in message
news:fu***************@no-mx.msusenet.com...

Hi Craig,

If you are developing on a Windows box:
Try these steps: create an ODBC link (system/user DSN) to your database
in your computer's "Data sources" interface
(Start...Programs...Administrat....etc).
Then test the connection and copy the connection string out of the
created
DSN and into your connection string in your code.

Give me a shout if that doesnt help. Just remember that on MySQL your
user has to have access to the localhost or your machine name needs to
be listed under your username in the MySQL database.

Enjoy old chap!
Fuzzymelon
--
fuzzymelon
------------------------------------------------------------------------
fuzzymelon's Profile: http://www.msusenet.com/member.php?userid=2457
View this thread: http://www.msusenet.com/t-1870552429

Nov 17 '05 #4

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

Similar topics

6
by: | last post by:
I am rewriting a C++ application in C#. This file has a combination of Text and Binary data. I used CFile before to read the text. If I hit a certain string that denotes the following data is...
1
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end...
1
by: Anand | last post by:
I just implemented a program to solve reader writter prob. Wenever I run the program it seems to go into S+ state and it waits there I dont know why. When i attach gdb to one of the childs and step...
5
by: Drew Yallop | last post by:
I read an XML file with a stream reader in VB.Net. When I look at the stream reader output in debug mode (by passing cursor over the stream reader object)the format is a perfect replica of the...
2
by: Patrick Olurotimi Ige | last post by:
Why do i get "Invalid attempt to FieldCount when reader is closed" Is the problem the way the datareader reads data as opposed to a dataset? When trying to compile this code:- Dim reader As...
4
by: Ram | last post by:
I am using ADO.Net data reader to retrieve data from main frame. I am getting timestamp which is 26 (yyyy-mm-dd hh- mm-ss.123456) bytes as sqltimestamp data type. I am using data reader to...
12
by: Jerry Camel | last post by:
Not sure if this is a good place to post this... I'm writing and ASP.net app using vb .net. I need to interact with a credit card reader. I have one that sits inline with the keyboard. Works...
3
by: John | last post by:
Hi I am getting the System.IndexOutOfRangeException was unhandled error on the last line of below code; Cmd = New OleDb.OleDbCommand("SELECT FROM ", LocalConn) Reader = Cmd.ExecuteReader()...
3
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, how do you resolve this problem? i have a public procedure in my DataAccessLayer that gets a SqlDataReader how do i close the reader from inside the DataAccessLayer if I'm returning...
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.