C#을 배우려고하면 쿼리를 수행하고 결과를 얻는 데 도움이되지 않습니다. C# .NET에서 아래의 작업을 수행하는 가장 좋은 방법과 방법을 모두 파악하려고합니다. 그것은 MySQL 데이터베이스입니다.동등한 C#이 PHP 코드의
//Interact with the DB. Find out if this hashed account #'s in there.
$dbh = $this->getPDO();
$procedure = "SELECT userPass FROM 499Users WHERE accName = :acc";
$call = $dbh->prepare($procedure);
$call->bindParam(':acc', $testAcc, PDO::PARAM_STR);
$call->execute();
//Fetch up to 1 result row
$row = $call->fetch(PDO::FETCH_ASSOC);
이 내 최신 시도이다 는 또한 내가 아마 매개 변수를 사용해야 실현,하지만 난 그냥이
MySqlConnectionStringBuilder conn_string = new MySqlConnectionStringBuilder();
conn_string.Server = "*";
conn_string.UserID = "*";
conn_string.Password = "*";
conn_string.Database = "*";
conn_string.Port = 3306;
MySqlConnection connection = new MySqlConnection(conn_string.ToString());
try
{
Console.WriteLine("Trying to connect to: ..." + conn_string); Console.WriteLine("Connecting to MySQL...");
connection.Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
string hashedAcc = this.HashPassword(acc);
//Verify hashed account
string query = "SELECT userPass FROM 49Users WHERE accName =" + hashedAcc;
MySqlCommand cmd = new MySqlCommand(query, connection);
MySqlDataReader myReader;
myReader = cmd.ExecuteReader();
try
{
while (myReader.Read())
{
Console.WriteLine(myReader.GetString(0));
}
}
finally
{
myReader.Close();
connection.Close();
}
무언가를 시도해 주셔서 감사합니다. 포함 해 주셔서 감사합니다. 그러나 C# 코드가 어떤 방식으로 실패합니까? 예외가 있습니까? 예상 된 결과가 아닙니까? –
예 : 'MySql.Data.MySqlClient.MySqlException'유형의 처리되지 않은 예외가 MySql.Data.CF.dll에서 발생했습니다. * 명령 실행 중 치명적인 오류가 발생했습니다. * – user2079828
스택 추적이 있습니까? 어떤 라인이 예외를 던지고 있는지 나타내는 어떤 지시? –