/*文件保存对话框,文件保存采用了一个file自定义类*/
SaveFileDialog saveFileDialog=new SaveFileDialog();
saveFileDialog.Filter= "Excel files(*.xls)|*.xls|All files(*.*)|*.*" ;
if(origin=="CallRecord")
{
saveFileDialog.Title="月末电话数据导入Excel";
}
else saveFileDialog.Title="月末信息发布数据导入Excel";
saveFileDialog.FilterIndex=1;
saveFileDialog.RestoreDirectory=true;
if(saveFileDialog.ShowDialog()==DialogResult.OK)
{
string fName=saveFileDialog.FileName;
File fSaveAs=new File(fName);
fSaveAs.WriteFile(fName);
}//if()
excel.Workbooks.Close();
excel.Quit();//关闭excel程序
}//try
catch(System.Exception e)
{
System.Console.WriteLine("something wrong happened about excel excution or dababase operation ",e);
}
}//connect
/*清空当前表内容*/
private void DeleteRecord(string record)
{
SqlConnection connection=creCon();
connection.Open();
string DeleteString="delete from "+record;
SqlCommand deleteCommand=new SqlCommand(DeleteString,connection);
deleteCommand.ExecuteNonQuery();
connection.Close();
}
/*数据库连接函数*/
public static SqlConnection creCon()
{
string sql="server=127.0.0.1;uid=sa;pwd=;database=zhaoxia";
SqlConnection con=new SqlConnection (sql);
return con;
}
/*主函数*/
static void Main ( )