using (INFOEYE_HELPDESKEntities db = new INFOEYE_HELPDESKEntities())
{
try
{
//读取文件
StreamReader sr = new StreamReader("D:\\1.txt");
int count = 0;
string sql = @"INSERT INTO [INFOEYE_HELPDESK].[dbo].[UserInformationList]
([Account],[Name],[Tele],[EMail],[Company] ,[Department]) VALUES ";
//循环每一行数据
while (true)
{
if (count % 500 == 0&&count>98)
{
sql += sql.TrimEnd(',') + @" INSERT INTO [INFOEYE_HELPDESK].[dbo].[UserInformationList]
([Account],[Name],[Tele],[EMail],[Company] ,[Department]) VALUES ";
}
string sdata = sr.ReadLine();
count = count + 1;
//如果是空的时候则停止
if (string.IsNullOrEmpty(sdata))
break;
string[] datac = sdata.Split('+');
string onlystr = " (";
for (int i = 0; i < datac.Length; i++)
{
onlystr += "N'" + datac[i] + "',";
}
sql += onlystr.TrimEnd(',') + "),";
}
sql += sql.TrimEnd(',');
db.ExecuteNativeQueryBySQL(sql)
}
catch (Exception ex)
{
}
}