Date:September 29, 2007 | Author:Mz | From:FuCity.Net
一,首先我们在SQL2000中导出SQL脚本
1,企业管理器中控制台根目录
选中你要导出的 数据库,右击选择 所有任务中的 生成SQL脚本.
2,在弹出的对话框中进行设置
单击 全部显示选中编写全部对象脚本复选框(当然你也可以跟据情分别选择)
设置格式选项卡中前两项要选中其它的跟据你的需要.
选项的选项卡中包含了更多细节设置(由其重要的是 主外键等约束关系见意选上).
确定以后保存起来,就是一个完整的SQL脚本了.
二,编写.net程序
1,新建个Web页编写.cs代码文件内容
一,首先我们在SQL2000中导出SQL脚本
1,企业管理器中控制台根目录
选中你要导出的 数据库,右击选择 所有任务中的 生成SQL脚本.
2,在弹出的对话框中进行设置
单击 全部显示选中编写全部对象脚本复选框(当然你也可以跟据情分别选择)
设置格式选项卡中前两项要选中其它的跟据你的需要.
选项的选项卡中包含了更多细节设置(由其重要的是 主外键等约束关系见意选上).
确定以后保存起来,就是一个完整的SQL脚本了.
二,编写.net程序
1,新建个Web页编写.cs代码文件内容
using
System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO; // 输入输出流命名空间
public class Lj
{
public static ArrayList ExecuteSqlFile( string varFileName)
{
//
// TODO:读取.sql脚本文件
//
StreamReader sr = File.OpenText(varFileName); // 传入的是文件路径及完整的文件名
ArrayList alSql = new ArrayList(); // 每读取一条语名存入ArrayList
string commandText = "" ;
string varLine = "" ;
while (sr.Peek() > - 1 )
{
varLine = sr.ReadLine();
if (varLine == "" )
{
continue ;
}
if (varLine != " GO " )
{
commandText += varLine;
commandText += " " ;
}
else
{
alSql.Add(commandText);
commandText = "" ;
}
}
sr.Close();
return alSql;
}
}
public partial class baidu : System.Web.UI.Page
{
protected void Page_Load( object sender, EventArgs e)
{
string constr = " data source=.;uid=sa;pwd=;database=lx " ; // 定义链接字符窜
SqlConnection conn = new SqlConnection(constr);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
ArrayList Lists = Lj.ExecuteSqlFile(Server.MapPath( " NetShop.sql " )); // 调用ExecuteSqlFile()方法,反回 ArrayList对象;
string teststr; // 定义遍历ArrayList 的变量;
foreach ( string varcommandText in Lists)
{
teststr = varcommandText; // 遍历并符值;
// Response.Write(teststr + "|@|<br>");
cmd.CommandText = teststr; // 为SqlCommand赋Sql语句;
cmd.ExecuteNonQuery(); // 执行
}
conn.Close();
}
}
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO; // 输入输出流命名空间
public class Lj
{
public static ArrayList ExecuteSqlFile( string varFileName)
{
//
// TODO:读取.sql脚本文件
//
StreamReader sr = File.OpenText(varFileName); // 传入的是文件路径及完整的文件名
ArrayList alSql = new ArrayList(); // 每读取一条语名存入ArrayList
string commandText = "" ;
string varLine = "" ;
while (sr.Peek() > - 1 )
{
varLine = sr.ReadLine();
if (varLine == "" )
{
continue ;
}
if (varLine != " GO " )
{
commandText += varLine;
commandText += " " ;
}
else
{
alSql.Add(commandText);
commandText = "" ;
}
}
sr.Close();
return alSql;
}
}
public partial class baidu : System.Web.UI.Page
{
protected void Page_Load( object sender, EventArgs e)
{
string constr = " data source=.;uid=sa;pwd=;database=lx " ; // 定义链接字符窜
SqlConnection conn = new SqlConnection(constr);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
ArrayList Lists = Lj.ExecuteSqlFile(Server.MapPath( " NetShop.sql " )); // 调用ExecuteSqlFile()方法,反回 ArrayList对象;
string teststr; // 定义遍历ArrayList 的变量;
foreach ( string varcommandText in Lists)
{
teststr = varcommandText; // 遍历并符值;
// Response.Write(teststr + "|@|<br>");
cmd.CommandText = teststr; // 为SqlCommand赋Sql语句;
cmd.ExecuteNonQuery(); // 执行
}
conn.Close();
}
}