C# 初始化数据库的问题
C# 初始化数据库的问题
数据库是sqlserver2000
有一个data.sql文件
里面有中文资料,但我写入到数据中全是乱码
我写入的方法:
public int ExecuteSqlScript(string sqlFile)
{
int returnValue = -1;
int sqlCount = 0, errorCount = 0;
if (!File.Exists(sqlFile))
{
//Log.WriteLog(string.Format("sql file not exists!", sqlFile));
return -1;
}
using (StreamReader sr = new StreamReader(sqlFile,Encoding.Unicode))
{
string line = string.Empty;
char spaceChar = ' ';
string newLIne = "\r\n", semicolon = ";";
string sprit = "/", whiffletree = "-";
string sql = string.Empty;
do
{
line = sr.ReadLine();
// 文件结束
if (line == null) break;
// 跳过注释行
if (line.StartsWith(sprit) || line.StartsWith(whiffletree)) continue;
// 去除右边空格
line = line.TrimEnd(spaceChar);
sql += line;
// 以分号(;)结尾,则执行SQL
if (sql.EndsWith(semicolon))
&n