473,387 Members | 1,517 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.

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 1501
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: 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: 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
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...
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,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.