添加sqldmo COM组件
SQLDMO.SQLServer2 sqlserver=new SQLDMO.SQLServer2Class();
sqlserver.Connect("localhost","sa","");
SQLDMO.Databases mydbs=sqlserver.Databases;
SQLDMO.Database mydb =new SQLDMO.DatabaseClass ();
mydb=(SQLDMO.Database)mydbs.Item("Test","sa");
System.IO.StreamReader s=new System.IO.StreamReader("E:/xp/testSqlDmo/a.sql");
string sql=s.ReadToEnd();
mydb.ExecuteImmediate(sql,SQLDMO.SQLDMO_EXEC_TYPE.SQLDMOExec_Default,sql.Length );
建立新表
SqlConnection conn=new SqlConnection("server=(local);user=sa;pwd=;database=master");
SqlCommand cmd=new SqlCommand("CREATE DATABASE [我的数据库] COLLATE Chinese_PRC_CI_AS;",conn);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();