日期:2014-05-17 浏览次数:21198 次
private void button1_Click(object sender, EventArgs e)
{
saveFileDialog1.Title = "保存的excel文件";
saveFileDialog1.InitialDirectory = "c:\\";
saveFileDialog1.Filter = "Excel97-2003 (*.xls)|*.xls|All Files (*.*)|*.*";
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName == "" || saveFileDialog1.FileName == null)
{
MessageBox.Show("文件名不能为空!");
return;
}
string path = saveFileDialog1.FileName;
string constr = "Data Source=.;Initial Catalog=Exhibition;User ID=sa;Password=";
string sql = GetStrSql();
DataSet ds=new DataSet();
using (SqlConnection con = new SqlConnection(constr))
{
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.Fill(ds);
}
if (ds == null)
{
MessageBox.Show("数据获取有误!");
return;