linq 查询 Linq 高级查询实例代码
投稿:whsnow
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.IO;
using System.Text;
using System.Data;
namespace SJLERP
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Dictionary<string, string> cityAndNum =
Regex.Matches(City.data, @"[^\r].*?\r")
.Cast<Match>()
.Select(c => Regex.Replace(c.Value, @"\s", ""))
.Aggregate(new Dictionary<string, string>(), (reval, item) =>
{
if (Regex.IsMatch(item, @"[\u4e00-\u9fa5]+\d+"))
{
string word = Regex.Match(item, @"[\u4e00-\u9fa5]+").Value;
string num = Regex.Match(item, @"\d+").Value;
reval.Add(word, num);
}
return reval;
});
ADOHelper.ExecuteCommand("create table KaixuanTest ( city varchar(max),num varchar(max) ) ");
cityAndNum.ToList().ForEach(c =>
{
string sql = string.Format(" insert KaixuanTest select '{0}','{1}'",c.Key,c.Value);
ADOHelper.ExecuteCommand(sql);
});
}
}
}