Esempio n. 1
0
        /// <summary>
        /// 根据联系人编号获取联系人信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Model.Contact GetModel(int Id)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append("select top 1 Id,Name,Phone,Email,QQ,WorkUnit,OfficePhone,HomeAddress,HomePhone,Memo,GroupId from Contact ");
            sql.Append("where Id=@Id");

            SqlParameter[] para =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            para[0].Value = Id;

            Model.Contact model = new Model.Contact();
            DataTable     dt    = SqlDbHelper.ExecuteDataTable(sql.ToString(), para);

            if (dt.Rows.Count > 0)
            {
                if (CheckDataTableCell(dt, 0, "Id"))
                {
                    model.Id = int.Parse(dt.Rows[0]["Id"].ToString());
                }
                if (CheckDataTableCell(dt, 0, "Name"))
                {
                    model.Name = dt.Rows[0]["Name"].ToString();
                }
                if (CheckDataTableCell(dt, 0, "Phone"))
                {
                    model.Phone = dt.Rows[0]["Phone"].ToString();
                }
                if (CheckDataTableCell(dt, 0, "Email"))
                {
                    model.Email = dt.Rows[0]["Email"].ToString();
                }
                if (CheckDataTableCell(dt, 0, "QQ"))
                {
                    model.QQ = dt.Rows[0]["QQ"].ToString();
                }
                if (CheckDataTableCell(dt, 0, "WorkUnit"))
                {
                    model.WorkUnit = dt.Rows[0]["WorkUnit"].ToString();
                }
                if (CheckDataTableCell(dt, 0, "OfficePhone"))
                {
                    model.OfficePhone = dt.Rows[0]["OfficePhone"].ToString();
                }
                if (CheckDataTableCell(dt, 0, "HomeAddress"))
                {
                    model.HomeAddress = dt.Rows[0]["HomeAddress"].ToString();
                }
                if (CheckDataTableCell(dt, 0, "HomePhone"))
                {
                    model.HomePhone = dt.Rows[0]["HomePhone"].ToString();
                }
                if (CheckDataTableCell(dt, 0, "Memo"))
                {
                    model.Memo = dt.Rows[0]["Memo"].ToString();
                }
                if (CheckDataTableCell(dt, 0, "GroupId"))
                {
                    model.GroupId = int.Parse(dt.Rows[0]["GroupId"].ToString());
                }

                return(model);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
 public SqlDataReader read(string sql, SqlParameter[] parameters)//读取操作
 {
     return(SqlDbHelper.ExecuteReader(sql.ToString(), CommandType.Text, parameters));
 }