项目列表:
注意代码:
public List<Model> Select(string id) { string sql = "select * from tblStudentInfo where 学号 like '%" + @id + "%'"; //string sql = "select * from tblStudentInfo where 学号 like '%@id%'"; SqlHelper helper = new SqlHelper(); using (DataTable dt = helper.ExecuteDataTable(sql, new SqlParameter("@id", id))) { if (dt.Rows.Count > 0) { List<Model> persons = new List<Model>(); for (int i = 0; i < dt.Rows.Count; i++) { Model person = new Model(); person.学号 = dt.Rows[i][0].ToString(); person.姓名 = dt.Rows[i][1].ToString(); person.年龄 = dt.Rows[i].IsNull(2) ? null : (int?)int.Parse(dt.Rows[i][2].ToString()); person.性别 = dt.Rows[i].IsNull(3) ? null : dt.Rows[i][3].ToString(); person.出生年月 = dt.Rows[i].IsNull(4) ? null : (DateTime?)DateTime.Parse(dt.Rows[i][4].ToString()); person.家庭住址 = dt.Rows[i][5].ToString(); person.备注 = dt.Rows[i].IsNull(6) ? null : dt.Rows[i][6].ToString(); persons.Add(person); } return persons; } } return null; }