111,131
社区成员
发帖
与我相关
我的任务
分享
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) == "select")
{
SqlDataReader dr;
dr = com.ExecuteReader();
while (dr.Read())
{
System.Console.WriteLine(dr[0].ToString());
}
}
else
{
com.ExecuteNonQuery();
System.Console.WriteLine("操作成功!");
}
System.Console.ReadLine();
}
}
class baseclass
{
public string sql(string filepath)
{
StreamReader str = null;
string sm = "";
try
{
str = File.OpenText(filepath);
while (str.Peek() != -1)
{
sm = str.ReadLine();
}
str.Close();
}
catch
{
sm = "";
}
return sm;
}
public void resoust(string sql)
{
}
}
}