这是一个调用数据库中的存储过程导出数据库中表格的程序,好象没有语法错误,但是未到处任何数据。请看一下,谢谢了!
存储过程为
CREATE PROCEDURE [dbo].[out]
@servername varchar(20), /*server name*/
@username varchar(20),
@password varchar(20),
@DatabaseName varchar(20), /*要导出表的数据库名字*/
@filepath varchar(100),
@TableName varchar(20) /*要导出数据库中表的名字*/
AS
BEGIN
declare @connStr varchar(400)
set @connStr=''bcp ''+@DatabaseName+''.dbo.''+@TableName+'' out ''+@filepath+'' -c -q -S ''+@servername+'' -U ''+@username+'' -P ''+ @password
exec ..xp_cmdshell @connStr
END
调用程序为 ( Default2.aspx.cs中的)
protected void Button6_Click(object sender, EventArgs e)
{
SqlConnection objConn = new SqlConnection();
objConn.ConnectionString = "data source=xieyulin;Persist Security Info=false;database=SDM;user id=gg;password=123456";
objConn.Open();
SqlCommand sqlcomm = new SqlCommand("out", objConn);
sqlcomm.CommandType = CommandType.StoredProcedure;
SqlParameter par1 = new SqlParameter("@servername", SqlDbType.VarChar, 20);
SqlParameter par2 = new SqlParameter("@username", SqlDbType.VarChar, 20);
SqlParameter par3 = new SqlParameter("@password", SqlDbType.VarChar, 20);
SqlParameter par4 = new SqlParameter("@Databasename", SqlDbType.VarChar, 20);
SqlParameter par5 = new SqlParameter("@filepath", SqlDbType.VarChar, 100);
SqlParameter par6 = new SqlParameter("@Tablename", SqlDbType.VarChar, 20);
sqlcomm.Parameters.Add(par1);
sqlcomm.Parameters.Add(par2);
sqlcomm.Parameters.Add(par3);
sqlcomm.Parameters.Add(par4);
sqlcomm.Parameters.Add(par5);
sqlcomm.Parameters.Add(par6);
par1.Direction = ParameterDirection.Input;
par2.Direction = ParameterDirection.Input;
par3.Direction = ParameterDirection.Input;
par4.Direction = ParameterDirection.Input;
par5.Direction = ParameterDirection.Input;
par6.Direction = ParameterDirection.Input;
string str1;
if (TextBox1.Text.ToString() == null)
{
Label1.Text = "提示:出错";
return;
}
else
str1 = TextBox1.Text.ToString();
string str2;
if (TextBox2.Text.ToString() == null)
{
Label1.Text = "提示:出错";
return;
}
else
str2 = TextBox2.Text.ToString();
string str3;
if (TextBox3.Text.ToString() == null)
{
Label1.Text = "提示:出错";
return;
}
else
str3 = TextBox3.Text.ToString();
string str4;
if (TextBox4.Text.ToString() == null)
{
Label1.Text = "提示:出错";
return;
}
else
str4 = TextBox4.Text.ToString();
par1.Value = str1;
par2.Value = str2;
par3.Value = str3;
par4.Value = str4;
for (int i = 0; i <= this.ListBox5.Items.Count - 1; i++)
{
string str6 = " ";
if (this.ListBox5.Items[i].Value != null)
{
str6 = this.ListBox5.Items[i].Value;
if (str6 == null)
return;
if (str6 == "Sheet1$")
{
par6.Value = "Sheet1$";
string FileName = DropDownList2.SelectedItem.Text + "/Sheet1$" + DropDownList3.SelectedItem.Text;
if (FileName != null)
{
if (File.Exists(FileName))
{
File.Delete(FileName);
}
File.Create(FileName);
string str5 = FileName.ToString();
par5.Value = str5;
sqlcomm.ExecuteNonQuery();
}
else
{
Label1.Text = "提示:文件导出失败";
return;
}
}
if (str6 == "期刊表")
{
par6.Value = "QKB";
string FileName = DropDownList2.SelectedItem.Text + "/期刊表" + DropDownList3.SelectedItem.Text;
if (FileName != null)
{
if (File.Exists(FileName))
{
File.Delete(FileName);
}
File.Create(FileName);
string str5 = FileName.ToString();
par5.Value = str5;
sqlcomm.ExecuteNonQuery();
}
else
{
Label1.Text = "提示:文件导出失败";
return;
}
}
}
}