public Model.Contact GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Name,Phone,Email,QQ,WorkUnit,OfficePhone,HomeAddress,HomePhone,[Memo],GroupId from Contact "); strSql.Append(" where Id=@Id"); OleDbParameter[] parameters = { new OleDbParameter("@Id", OleDbType.Integer, 4) }; parameters[0].Value = Id; Model.Contact model = new Model.Contact(); DataTable dt = OleDbHelper.ExecuteDataTable(strSql.ToString(), parameters); if (dt.Rows.Count > 0) { if (dt.Rows[0]["Id"] != null && dt.Rows[0]["Id"].ToString() != "") { model.Id = int.Parse(dt.Rows[0]["Id"].ToString()); } if (dt.Rows[0]["Name"] != null && dt.Rows[0]["Name"].ToString() != "") { model.Name = dt.Rows[0]["Name"].ToString(); } if (dt.Rows[0]["Phone"] != null && dt.Rows[0]["Phone"].ToString() != "") { model.Phone = dt.Rows[0]["Phone"].ToString(); } if (dt.Rows[0]["Email"] != null && dt.Rows[0]["Email"].ToString() != "") { model.Email = dt.Rows[0]["Email"].ToString(); } if (dt.Rows[0]["QQ"] != null && dt.Rows[0]["QQ"].ToString() != "") { model.QQ = dt.Rows[0]["QQ"].ToString(); } if (dt.Rows[0]["WorkUnit"] != null && dt.Rows[0]["WorkUnit"].ToString() != "") { model.WorkUnit = dt.Rows[0]["WorkUnit"].ToString(); } if (dt.Rows[0]["OfficePhone"] != null && dt.Rows[0]["OfficePhone"].ToString() != "") { model.OfficePhone = dt.Rows[0]["OfficePhone"].ToString(); } if (dt.Rows[0]["HomeAddress"] != null && dt.Rows[0]["HomeAddress"].ToString() != "") { model.HomeAddress = dt.Rows[0]["HomeAddress"].ToString(); } if (dt.Rows[0]["HomePhone"] != null && dt.Rows[0]["HomePhone"].ToString() != "") { model.HomePhone = dt.Rows[0]["HomePhone"].ToString(); } if (dt.Rows[0]["Memo"] != null && dt.Rows[0]["Memo"].ToString() != "") { model.Memo = dt.Rows[0]["Memo"].ToString(); } if (dt.Rows[0]["GroupId"] != null && dt.Rows[0]["GroupId"].ToString() != "") { model.GroupId = int.Parse(dt.Rows[0]["GroupId"].ToString()); } return(model); } else { return(null); } }