c#执行sql脚本的问题

来源:百度知道 编辑:UC知道 时间:2024/06/20 07:13:11
我希望写个程序,调用cmd.exe执行sqlplus,然后执行指定的.sql脚本,数据库是oracle9i的。请问c#中应该怎么实现?

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data.SqlClient;

namespace openfile
{
class Program
{
static void Main(string[] args)
{
baseclass bs=new baseclass();
System.Console.WriteLine("请输入路径(例'c://cmd.sql')");//输入你要执行文件的目录
string path=System.Console.ReadLine();
string sql=bs.sql(path);
int i = 0;
SqlConnection con = new SqlConnection("server=.;database=oracle9i;user id=sa;password=123");//可以根据你自己的机子设置的数据库,用户名,密码而定
SqlCommand com = new SqlCommand(sql,con);
con.Open();
for (; i < sql.Length; i++)
{
if (sql.Substring(i, 0) != " ")
break;
}
if(sql.Substring(i,6)=="