もう一度、エクスポートデータベースでExcelに表示されるアプリケーションに最後の問題があります。下のコードを見ると、私は2つの異なるコードブロックを使用しましたが、エクスポートプロセスの後ではExcelファイルを開いたときに不幸にもエラーが発生し、何も表示されません。C#Winforms:ExcelデータベースへのMysqlデータベースのエクスポート
エラー通知ウィンドウ:ファイルが壊れているか、動作していない可能性があります。ファイル形式または拡張子が一致しません。
これらのコードブロックについては、Google CodeプロジェクトのExcelライブラリを私のソリューションの 'Referance'に追加しました。
using ExcelLibrary.CompoundDocumentFormat;
using ExcelLibrary.SpreadSheet;
using ExcelLibrary.BinaryDrawingFormat;
using ExcelLibrary.BinaryFileFormat;
// Original code block, first i used:
string myConnection = "datasource=root;port=root;username=root;password=root";
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlCommand cmdDataBase = new MySqlCommand("select name,surname,birth,telephone,email,city,adress,recorddate from doguAkdenizApp.team;", myConn);
try
{
MySqlDataAdapter dataAdapter = new MySqlDataAdapter();
dataAdapter.SelectCommand = cmdDataBase;
dbdataset = new DataTable();
dataAdapter.Fill(dbdataset);
BindingSource bSource = new BindingSource();
bSource.DataSource = dbdataset;
dgvEkip.DataSource = bSource;
dataAdapter.Update(dbdataset);
DataSet dataSet = new DataSet("ekipDataset");
dataSet.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;
dataAdapter.Fill(dbdataset);
dataSet.Tables.Add(dbdataset);
ExcelLibrary.DataSetHelper.CreateWorkbook("ekipDataset.xls", dataSet);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
コードブロックは、上記の私は、インターネット上でこれを見つけたが、このブロックはうまく
string myConnection = "datasource=root;port=root;username=root;password=root";
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlCommand cmdDataBase = new MySqlCommand("select name,surname,birth,telephone,email,city,adress,recorddate from doguAkdenizApp.team;", myConn);
MySqlDataAdapter dataAdapter = new MySqlDataAdapter();
dataAdapter.SelectCommand = cmdDataBase;
dbdataset = new DataTable();
dataAdapter.Fill(dbdataset);
BindingSource bSource = new BindingSource();
bSource.DataSource = dbdataset;
dgvEkip.DataSource = bSource;
dataAdapter.Update(dbdataset);
dbdataset.WriteXml("Ekip_Dataset.xls"); //I am not sure why he used "WriteXml" but i tried as this
MessageBox.Show("Dosya basariyla olusturulmustur.");
だから何の問題がここにあるか、Excelにデータベースをエクスポートする別の方法がありますが動作しませんでした動作しませんでしたか?同様に、私はどのように私はユーザーにファイルを保存する場所を選択させることができます興味がありますか?
エラーは何ですか? –