我正在读取 c#.net 中的文本文件,最后一行完全为空,但在 foreach c# 中无法检测到空字符串,因此出现错误
string[] lines = System.IO.File.ReadAllLines(dir);
List<KeyValuePair<int, DateTime>> items = new List<KeyValuePair<int, DateTime>>();
List<KeyValuePair<int, DateTime>> lst = new List<KeyValuePair<int, DateTime>>();
foreach (string line in lines)
{
if (line!=string.Empty)
{
l = line.Split('\t');
l[0] = l[0].Trim();
PersianCalendar persCal = new PersianCalendar();
SqlConnection sqlconn = new SqlConnection(DBsetting.Connstring);
SqlCommand sqlda = new SqlCommand("InsertReadd", sqlconn);
sqlda.CommandType = CommandType.StoredProcedure;
sqlda.Parameters.AddWithValue("@date", l[1]);
sqlda.Parameters.AddWithValue("@IDp", l[0]);
sqlda.Parameters.AddWithValue("@day", GetDayOfWeek(GetPerDate(l[1])));
sqlda.Parameters.AddWithValue("@nobatkari", "");
sqlda.Connection.Open();
sqlda.ExecuteNonQuery();
sqlda.Connection.Close();
}
}
RefGrid();