SqlConnection sqlConnection1 = null; string filePath = FileUpload1.PostedFile.FileName; sqlConnection1 = new SqlConnection();
sqlConnection1.ConnectionString = "server=(local);integrated security=SSPI;initial catalog=work"; //import excel into SQL Server 2000
/*string importSQL = "SELECT * into live41 FROM OpenDataSource" +
"('Microsoft.Jet.OLEDB.4.0','Data Source=" + "\"" + "E:\\022n.xls" + "\"" +
"; User ID=;Password=; Extended properties=Excel 5.0')...[Sheet1$]";*/ //export SQL Server 2000 into excel
string exportSQL = @"EXEC master..xp_cmdshell
'bcp Library.dbo.live41 out " + filePath + "-c -q -S" + "\"" + "\"" +
" -U" + "\"" + "\"" + " -P" + "\"" + "\"" + "\'"; //重点是这句不知道是什么意思,整个代码调试了,没有出现问题 我运行了这些sp_configure 'show advanced options',1
//reconfigure
//go
//sp_configure 'xp_cmdshell',1
//reconfigure
//go
//reconfigure
//代码执行了,没有提示出错,但是没有看到我的那个execl的数据,求高人指点下
try
{
sqlConnection1.Open();
//SqlCommand sqlCommand1 = new SqlCommand();
//sqlCommand1.Connection = sqlConnection1;
//sqlCommand1.CommandText = importSQL;
//sqlCommand1.ExecuteNonQuery();
//MessageBox.Show("import finish!");
SqlCommand sqlCommand2 = new SqlCommand();
sqlCommand2.Connection = sqlConnection1;
sqlCommand2.CommandText = exportSQL;
sqlCommand2.ExecuteNonQuery();
Response.Write("export finish!");
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
}
sqlConnection1.ConnectionString = "server=(local);integrated security=SSPI;initial catalog=work"; //import excel into SQL Server 2000
/*string importSQL = "SELECT * into live41 FROM OpenDataSource" +
"('Microsoft.Jet.OLEDB.4.0','Data Source=" + "\"" + "E:\\022n.xls" + "\"" +
"; User ID=;Password=; Extended properties=Excel 5.0')...[Sheet1$]";*/ //export SQL Server 2000 into excel
string exportSQL = @"EXEC master..xp_cmdshell
'bcp Library.dbo.live41 out " + filePath + "-c -q -S" + "\"" + "\"" +
" -U" + "\"" + "\"" + " -P" + "\"" + "\"" + "\'"; //重点是这句不知道是什么意思,整个代码调试了,没有出现问题 我运行了这些sp_configure 'show advanced options',1
//reconfigure
//go
//sp_configure 'xp_cmdshell',1
//reconfigure
//go
//reconfigure
//代码执行了,没有提示出错,但是没有看到我的那个execl的数据,求高人指点下
try
{
sqlConnection1.Open();
//SqlCommand sqlCommand1 = new SqlCommand();
//sqlCommand1.Connection = sqlConnection1;
//sqlCommand1.CommandText = importSQL;
//sqlCommand1.ExecuteNonQuery();
//MessageBox.Show("import finish!");
SqlCommand sqlCommand2 = new SqlCommand();
sqlCommand2.Connection = sqlConnection1;
sqlCommand2.CommandText = exportSQL;
sqlCommand2.ExecuteNonQuery();
Response.Write("export finish!");
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
}
解决方案 »
- 阿拉伯数字生成随机数,一道面试题,进来瞧瞧
- 【号外号外=====100分分求帮助】--关于一个js的
- Lambada表达式里排序的问题!!!!!!!!!!!!!!!!!!!
- 为什么我的文件依赖缓存,文件没改变的情况下,半个小时就失效了?
- 怎样将这个分页存储过程中的临时表换成表变量实现呀
- 上传文件问题!!!
- 在线等高人 如何为选择菜单设置背景颜色?
- 如何向SQL SERVER2000数据库中字段写入带换行字符的数据?
- 请问这样获得客户机的名字和IP
- 请问如何在ASP.Net中发通过Smtp发邮件,好象.Net中提供的方法无法收到邮件,无法进行身份验证
- 【VS与IIS同步】
- vs2008连接数据库做查询分页
EXEC master..xp_cmdshell\r\n'bcp Library.dbo.live41 out C:\\Documents and Settings\\Administrator\\桌面\\新建文件夹 (2)\\个体数据.xls-c -q -S\"\" -U\"\" -P\"\"'
我想要我的这个个体数据。xls的这个里边的数据,但是这句话放在sql里边就错误
master..xp_cmdshell 这里还".."改"."吧
然后怎么还有"\r\n" 你回车换行了,改这样这么写试试
string exportSQL = @"EXEC master.xp_cmdshell 'bcp Library.dbo.live41 out " + filePath + "-c -q -S" + "\"" + "\"" + " -U" + "\"" + "\"" + " -P" + "\"" + "\"" + "\'";
自己还是看看有没有这个function : xp_cmdshell