自社の課題で管理アプリケーションというものを行っているのですが、
C#でログイン認証をという機能やっているのですが、
うまくログインの認証ができずになっています。
ログイン認証をうまくいくにはどう書いていったらよろしいでしょうか?
ご教示の程、宜しくお願い致します。
こちらの処理でエラーが起こっているところです。
if (this.Form1.cs.txt.ID == dt.Rows[0].ToString())
{
//該当があった時の処理
}
//DB接続しログインの認証をさせる
try
{
//データベース接続を確立させる
string sConnectionString;
sConnectionString = "Server=localhost;Database=mysql;uid=root;pwd=root;";
MySqlConnection conn = new MySqlConnection(sConnectionString);
conn.Open();
//データベースとDatasetオブジェクトの間のリンクを表すDataAdapterを作成 MySqlDataAdapter sa = new MySqlDataAdapter("SELECT * FROM password_list WHERE HASH", conn); //DataAdapterの呼び出し DataSet ds = new DataSet(); sa.Fill(ds); DataTable dt; dt = ds.Tables["password_list"]; //DataTableのRowsコレクションに含まれるすべてのDataRowオブジェクトを読み込み foreach (DataRow drCurrent in dt.Rows) { Console.WriteLine( drCurrent["ID"].ToString(), drCurrent["PASSWORD"].ToString()); } Console.ReadLine(); conn.Close(); } catch (MySqlException ex) { Console.WriteLine(ex.Message); } //入力されたIDとPasswordの該当があるか確認 if (this.Form1.cs.txt.ID == dt.Rows[0].ToString()) { //該当があった時の処理 } //該当がなかった時の処理 MessageBox.Show("IDが認識しませんでした。"); Form2 form = new Form2(); form.ShowDialog();
ログイン認証をして、次のフォームに移行する処理を試してみたい認識です。
C#
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。