资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

mssql脱库脚本aspx版本-创新互联

<%@ Page Language=”C#” %>
 

 

 
protected void Button1_Click(object sender, EventArgs e)
{
string serverIP=txtServerIP.Text;
string database=txtDatabase.Text;
string user=txtUser.Text;
string pass=txtPass.Text;
string tableName=txtTableName.Text;
string colName=txtColName.Text;
string fileName=txtFileName.Text;
 
if (serverIP != null & database != null & user != null & pass != null & tableName != null & fileName != null)
{
 
string connectionString = “server=”+serverIP+”;database=”+database+”;uid=”+user+”;pwd=”+pass;
System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connectionString);
 
try
{
 
connection.Open();
string sqlStr = “select * from “+tableName;
 
if (colName!=”")
{
 
sqlStr = “select ” + colName + ” from ” + tableName;
 
}
 
System.Data.DataSet ds = new System.Data.DataSet();
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sqlStr, connection);
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);
da.Fill(ds);
System.Data.DataTable dataTable = ds.Tables[0];
 
if (dataTable.Rows.Count==0)
{
lblInfo.Text = “没有需要导出的数据!”;
lblInfo.ForeColor = System.Drawing.Color.Blue;
return;
 
}
string filePath = System.IO.Path.GetDirectoryName(Server.MapPath(“DataOutExl.aspx”))+”\DataOut”;
if (!System.IO.Directory.Exists(filePath))
{
System.IO.Directory.CreateDirectory(filePath);
}
bool outType = RadioButton1.Checked;
int sum = dataTable.Rows.Count;
int count = 1;
int size = 0;
int tmpNum = 1;
 
if (txtNum.Text!=”")
{
size = int.Parse(txtNum.Text);
count = sum / size+1;
}
for (int z = 0; z < count; z++)
{
 
Button1.Text = “正在导出..”;
Button1.Enabled = false;
lblInfo.Text = “正在导出第”+(z+1)+”组数据,共”+count+”组数据”;
lblInfo.ForeColor = System.Drawing.Color.Blue;
 
System.IO.StreamWriter file = new System.IO.StreamWriter(filePath+”\” + (z+1) +”_”+fileName, false, Encoding.UTF8);
 
bool isFirst = true;
if (outType)
{
 
file.Write(@”

Export Table”);
 
file.Write(“”);
 
}
 
for (int i = size*z; i < dataTable.Rows.Count; i++)
{
System.Data.DataRow dataRow = dataTable.Rows[i];
if (isFirst)
{
if ( outType)
{
file.Write(“”);
}
 
for (int j = 0; j < dataTable.Columns.Count; j++)
{
 
if (outType)
{
file.Write(“”);
}
 
file.Write(dataTable.Columns[j].ColumnName + “     “);
 
if (outType)
{
file.Write(“”);
}
}
 
if (outType)
{
file.Write(“”);
}
 
isFirst = false;
}
 
if (outType)
{
file.Write(“”);
}
else
{
file.WriteLine(” “);
}
 
for (int k = 0; k < dataTable.Columns.Count; k++)
{
 
if (outType)
{
file.Write(“”);
}
 
file.Write(dataTable.Rows[i][k] + “     “);
 
if (outType)
{
file.Write(“”);
}
}
 
if (outType)
{
file.Write(“”);
}
else
{
file.WriteLine(” “);
}
 
if (tmpNum==size)
break;
 
tmpNum += 1;
 
}
 
if (outType)
{
file.Write(“”);
file.Write(“
执行成功!返回” + tmpNum + “行
”); file.Write(“”); } else { file.WriteLine(“执行成功!返回” + tmpNum + “行!”); }   file.Dispose(); file.Close(); tmpNum = 1; }   lblInfo.Text = “导出成功!”; lblInfo.ForeColor = System.Drawing.Color.Blue; Button1.Enabled = true; Button1.Text = “开始导出”;   } catch (Exception ex) { lblInfo.Text = “导出失败!” + ex.Message; lblInfo.ForeColor = System.Drawing.Color.Red;   }finally { connection.Close(); }   } else { lblInfo.Text = “请先填写相关的连接信息!”; lblInfo.ForeColor = System.Drawing.Color.Red; } }   无标题页 .style1 { width: 61%; } .style2 { height: 23px; }
  SQL Server 数据导 出           By:闪电小子      
服务器IP: *
数据库: *
用户名: *
密码: *
表名: *
列名:   列名之间请用‘,’分开,不写代表全部
分组行数:   对于数据多的时候可以使用
保存文件名: *
文件格式:        
 

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

成都创新互联公司是一家专业从事做网站、成都网站制作、网页设计的品牌网络公司。如今是成都地区具影响力的网站设计公司,作为专业的成都网站建设公司,成都创新互联公司依托强大的技术实力、以及多年的网站运营经验,为您提供专业的成都网站建设、营销型网站建设及网站设计开发服务!
网页标题:mssql脱库脚本aspx版本-创新互联
当前URL:http://cdkjz.cn/article/ehipe.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220