Reader problem...

C

Craig Lister

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: (e-mail address removed)
 
M

Moty Michaely

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 said:
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: (e-mail address removed)
 
C

Craig Lister

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top