日期:2014-05-17 浏览次数:20985 次
string sqlText = "server=localhost;initial catalog=TEST; integrated security=true;user id =sa;password = 123456"; string sqlstr = "select 系数文件 from 基本_部件 where 部件ID=6"; SqlConnection conn = new SqlConnection(sqlText); conn.Open(); SqlCommand comm = new SqlCommand(sqlstr, conn); //读取测试 SqlDataReader dr = comm.ExecuteReader(); while (dr.Read()) { Byte[] raw = (Byte[])dr[0]; string result = System.Text.Encoding.GetEncoding("GB2312").GetString(raw); textBox1.Text = result; } dr.Close(); conn.Close();
string result = "12\t100.34\r\n13\t100.35\r\n14\t100.36\r\n15\t100.37\r\n16\t100.38\r\n17\t100.39\r\n18\t100.4\r\n19\t100.41\r\n20\t100.42\r\n21\t100.43\r\n22\t100.44\r\n23\t100.45\r\n24\t100.46\r\n25\t100.47\r\n"; var temp_result = Regex.Matches(result, @"(\d+)\s(\d+(\.\d+)?)").Cast<Match>().Select(a => new { ID=a.Groups[1].Value,Value=a.Groups[2].Value}); /* + [0] { ID = "12", Value = "100.34" } <Anonymous Type> + [1] { ID = "13", Value = "100.35" } <Anonymous Type> + [2] { ID = "14", Value = "100.36" } <Anonymous Type> + [3] { ID = "15", Value = "100.37" } <Anonymous Type> + [4] { ID = "16", Value = "100.38" } <Anonymous Type> + [5] { ID = "17", Value = "100.39" } <Anonymous Type> + [6] { ID = "18", Value = "100.4" } <Anonymous Type> + [7] { ID = "19", Value = "100.41" } <Anonymous Type> + [8] { ID = "20", Value = "100.42" } <Anonymous Type> + [9] { ID = "21", Value = "100.43" } <Anonymous Type> + [10] { ID = "22", Value = "100.44" } <Anonymous Type> + [11] { ID = "23", Value = "100.45" } <Anonymous Type> + [12] { ID = "24", Value = "100.46" } <Anonymous Type> + [13] { ID = "25", Value = "100.47" } <Anonymous Type> */