Hi,
I have this C# code to make a SELECT that follows my signature.
I'm sorry for the lame question, but although I've been a Linux and DB administrator for 15 years, I'm a total newbie to C# and MyDirect.NET.
I've read MyDirect manual and FAQ, but I didn't found what I'm looking for.
My question is, this SELECT statement returns a single value, a string.
How do I fetch it, i. e., how do I put the value coming from the SELECT statement into a variable ?
Any help would be appreciated.
Warm Regards,
Mário Gamito
public void selectMyValue ()
{
string MyConnectionString;
myConnectionString="";
if (myConnectionString="")
{
myConnectionString="User Id=vpopmail; Host=192.168.1.4; Database="vpopmail"; Password="secret";
string myResult = "SELECT sha FROM vpopmail WHERE pw_name = 'gamito'";
MySQLCommand MyCommand = new MySQLCommand(myResult);
myCommand.Connection = myConn;
myConn.Open();
try
{
myCommand.ExecuteNonQuery();
}
catch (Excepction MyException)
{
Response.Write("Connection Error: " + MyException.Message);
}
myConn.Close();
}
Question about SELECT
-
- Posts: 729
- Joined: Thu 13 Dec 2007 10:24
Hi!
Well it's quite easy.
You might use myCommand.ExecuteNonQuery(); with not SELECT statements.
If you would like to get data from a database you might want to use a MySqlDataReader instance.
Please see the following sample:Have you seen provided samples in the Start menu? They are really helpful.
Well it's quite easy.
You might use myCommand.ExecuteNonQuery(); with not SELECT statements.
If you would like to get data from a database you might want to use a MySqlDataReader instance.
Please see the following sample:
Code: Select all
string mySelectQuery = "SELECT sha FROM vpopmail WHERE pw_name = 'gamito'";
MySqlConnection myConnection = new MySqlConnection(myConnString);
MySqlCommand myCommand = new MySqlCommand(mySelectQuery, myConnection);
myConnection.Open();
MySqlDataReader myReader = myCommand.ExecuteReader();
string result;
try {
while (myReader.Read()) {
result = myReader.GetString(0);
}
} finally {
myReader.Close();
myConnection.Close();
}