/// <summary>
/// 读取sql脚本文件,注意:文件以utf-8格式保存
/// 每个执行单元,以独占一行的go结束
/// 可执行建表,修改表结构等操作
/// </summary>
/// <param name="varFileName"></param>
/// <returns></returns>
public static List<string> SqlFileToList(string varFileName)
{
if (!File.Exists(varFileName))
{
return null;
}
StreamReader sr = File.OpenText(varFileName);
List<string> alSql = new List<string>();
string commandText = "";
string varLine = "";
while (sr.Peek() > -1)
{
varLine = sr.ReadLine();
if (varLine.Trim() == "")
{
continue;
}
if (varLine.ToUpper().Trim() != "GO")
{
commandText +=" "+ varLine;
//commandText += "/r/n";
}
else
{
alSql.Add(commandText);
commandText = "";
}
}
sr.Close();
return alSql;
}