110,552
社区成员
发帖
与我相关
我的任务
分享
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
con.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from tableN", con);
da.Fill(ds);
DataTable dt = ds.Tables[0];
da.Dispose();
con.Close();
Stopwatch sw = new Stopwatch();
sw.Start();
//为了不相互干扰,是分2次执行的,每次具体时间不等,但大小关系确定
var Res1 = dt.Select("Col like '%xxxxxxx%'"); //00:00:00.3655990
//var Res1 = dt.DefaultView.RowFilter="Col like '%xxxxxxxx%'"; //00:00:00.2471333
sw.Stop();
}
catch
{
//...........
}
class Model
{
public string Col1{set;get;}
public string Col2 { set; get; }
public DateTime Col3 { set; get; }
public string Col4 { set; get; }
public string Col5 { set; get; }
}
List<Model> list = new List<Model>();
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
con.Open();
SqlCommand com = new SqlCommand("select * from tableN", con);
SqlDataReader dr = com.ExecuteReader();
while(dr.Read())
{
list.Add(new Model() { Col1 = dr["Col1"].ToString().Trim(), Col2 = dr["Col2"].ToString().Trim(), Col3 = Convert.ToDateTime(dr["Col3"].ToString().Trim()), Col4 = dr["Col4"].ToString().Trim(), Col5 = dr["Col5"].ToString().Trim() });
}
com.Dispose();
con.Close();
Stopwatch sw = new Stopwatch();
sw.Start();
var Res1 = list.Where(o => o.Col1.IndexOf("xxxxxxxxx")>=0).ToList(); //00:00:00.6017635
sw.Stop();
}
catch
{
//...........
}
写的比较匆忙