我在最後一個行是完全無效,但在的foreach C#中無法檢測空字符串,因此它的錯誤如何檢查是否字符串是在C#.NET空
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();
閱讀文本文件在C#.NET
你在找'String.IsNullOrEmpty' –
你應該包括你實際得到的錯誤。 – Sayse
'string.IsNullOrWhiteSpace'是一個不錯的選擇 –