/// <summary>
/// 把預定內容導入到Text文檔
/// </summary>
private void ChangeDbToText()
{
this.RecNum.Visible=true;
//建立文件,並打開
string oneLine = "";
string filename = "Storage Card/YD"+ DateTime.Now.ToString("yyyyMMddhhmmss")+".txt";
FileInfo finfo = new FileInfo(filename);
StreamWriter w = finfo.CreateText();
w.BaseStream.Seek(0, SeekOrigin.End);
SqlCeCommand sqlTable = Mc.gConn.CreateCommand();
sqlTable.CommandText = "select * from YDK ";
SqlCeDataReader Dr=sqlTable.ExecuteReader();
try
{
int i=0;
while(Dr.Read())
{
//輸出一條到文件
oneLine = Dr["ISBN"].ToString().PadRight(20,'' '')+Dr["BookNum"].ToString().PadRight(10,'' '')+Dr["Rdate"].ToString().PadRight(10,'' '')+" "+Dr["ShuShang"].ToString().PadRight(10,'' '');
w.WriteLine(oneLine);
i+=1;
if(i%100==0)
{
this.RecNum.Text=i.ToString();
this.RecNum.Refresh();
}
}
//關閉文件
w.Close();
MessageBox.Show("成功導出"+i.ToString().Trim()+"條!");
this.RecNum.Visible=false;
Dr.Close();
}
catch
{
MessageBox.Show("未導出數據!");
this.RecNum.Visible=false;
Dr.Close();
}