日期:2014-05-17 浏览次数:20883 次
string[] ssArray = s.Split('#'); for (int j = 2; j <= ssArray.GetUpperBound(0); j++) { string[] sArray = ssArray[j].Split(','); string sql1 = "insert into ww_test values" + "('"+ sArray[0] + "','" + sArray[1] + "','" + sArray[2] + "','" + sArray[3] + "','" + sArray[4] + "',')"; ocomm.CommandText = sql1; ocomm.ExecuteNonQuery(); } }
string s = "BJ#001#Q31,500,2000#Q24,500,2000#Q04,600,2500#Q35,650,2500#Q48,700,3200#Q42,750,3500#Q66,800,4000#"; Match match = Regex.Match(s, @"(?<cityId>\w+)#(?<marketId>\w+)(?<value>.+)"); string cityId = match.Groups["cityId"].Value; string marketId = match.Groups["marketId"].Value; string[] rows = match.Groups["value"].Value.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries); foreach (string row in rows) { string[] columns = row.Split(','); string sqlStr = string.Format("insert into 表名 values('{0}','{1}','{2}','{3}','{4}')", cityId, marketId, columns[0], columns[1], columns[2]); Response.Write(sqlStr + "<br/>"); }