Newbie question: Database

  • Thread starter Thread starter Craig Lister
  • Start date Start date
C

Craig Lister

I have a mySQL database.
I have two edit boxes. editID and editEMail.

I'd like to have the user enter a user ID into the editID, and press 'Find'.

A query must run as 'Select email from users where id = ' . editID.text

The result should then appear in the editEMail.

No, it's not a school project. I'm a Delphi developer (Ok, enough of the
boo-ing!) wanting to change to c#, and with this simple example working, I
believe I can progress. But I can't seem to find a good example using mySQL.

Anyone able to assist?

Craig

Websites:
http://www.thelisters.co.uk/
http://www.myschoolmates.com/
 
Craig said:
I have a mySQL database.
I have two edit boxes. editID and editEMail.

I'd like to have the user enter a user ID into the editID, and press 'Find'.

A query must run as 'Select email from users where id = ' . editID.text

The result should then appear in the editEMail.

No, it's not a school project. I'm a Delphi developer (Ok, enough of the
boo-ing!) wanting to change to c#, and with this simple example working, I
believe I can progress. But I can't seem to find a good example using mySQL.

Anyone able to assist?
You will either need a managed provider for MySql (I think someone
developed one) or you could use the OleDb provider or Odbc provider (I
think).

Then, you need a datareader, command, connection etc..
ie

WARNING! flycode ahead

string ConnectionString = "blah";
OledbConnection Connection = new OledbConnection(ConnectionString);
OledbCommand Command = new OledbCommand(Connection);
Command.CommandText = "SELECT Blah FROM Blah WHERE BlahId = @BlaId";
OledbParameter Parameter = Command.CreateParameter();
Parameter.ParameterName = "@BlaId";
Parameter.Value = BlahId;
OledbDataReader = Reader = Command.ExecuteReader();
while(Reader.Read())
{
console.writeline(Reader["BlahColumn"].ToString());
}

//close and dispose as necessary.

JB
 
Fantastic! Exactly what I was looking for... I shall now start my c#
database application creation attempt based on this. Thanks very much!

Craig
John B said:
Craig said:
I have a mySQL database.
I have two edit boxes. editID and editEMail.

I'd like to have the user enter a user ID into the editID, and press
'Find'.

A query must run as 'Select email from users where id = ' . editID.text

The result should then appear in the editEMail.

No, it's not a school project. I'm a Delphi developer (Ok, enough of the
boo-ing!) wanting to change to c#, and with this simple example working,
I believe I can progress. But I can't seem to find a good example using
mySQL.

Anyone able to assist?
You will either need a managed provider for MySql (I think someone
developed one) or you could use the OleDb provider or Odbc provider (I
think).

Then, you need a datareader, command, connection etc..
ie

WARNING! flycode ahead

string ConnectionString = "blah";
OledbConnection Connection = new OledbConnection(ConnectionString);
OledbCommand Command = new OledbCommand(Connection);
Command.CommandText = "SELECT Blah FROM Blah WHERE BlahId = @BlaId";
OledbParameter Parameter = Command.CreateParameter();
Parameter.ParameterName = "@BlaId";
Parameter.Value = BlahId;
OledbDataReader = Reader = Command.ExecuteReader();
while(Reader.Read())
{
console.writeline(Reader["BlahColumn"].ToString());
}

//close and dispose as necessary.

JB


 

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

Back
Top