ローカル データベースからテーブルを取得して .txt にダウンロードしようとしています。私は正直言って途方に暮れています。
他のユーザーが簡単に使用できるように、txt に含める必要があります。いくつかの方法を試しましたが、データグリッドに書き込んでいるかのように呼び出そうとしましたが、うまくいきませんでした。
Reader @ から結果を取得しています
while (dbReader.Read())
{
MessageBox.Show(dbReader.GetValue(0).ToString());
}
つまり、情報をプルして読み取っていますが、txt ファイルに書き込んでいるわけではありません。これがコードです。
private void btnDLSql_Click(object sender, RoutedEventArgs e)
{
string dbConnection = "datasource=127.0.0.1;port=3306;username=root;password=12345";
MySqlConnection conDataBase = new MySqlConnection(dbConnection);
MySqlCommand SelectCommand = new MySqlCommand("select GUID,BanTime,Reason from bans.bans order by BanType asc", conDataBase);
conDataBase.Open();
MySqlCommand command = conDataBase.CreateCommand();
MySqlDataReader dbReader = SelectCommand.ExecuteReader();
if (dbReader != null)
{
System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\mccla\Desktop\A3Bans.txt", true);
while (dbReader.Read())
{
MessageBox.Show(dbReader.GetValue(0).ToString());
}
}
conDataBase.Close();
}
どんな助けでも大歓迎です。質問で申し訳ありませんが、私は通常、自分で物事を理解しようとします。しかし、これに関する情報を見つけることができません。