Ado.net 类扩展属性

1、要扩展的类名字一样,2个类加(partial)

小例子:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Stores 扩展属性(扩展一个Stores类)
/// </summary>
public partial class Stores
{
    private SqlConnection _conn;
    private SqlCommand _cmd;
    private SqlDataReader _dr;

    public Stores()
    {
        _conn = DBconnection.conn;
        _cmd = _conn.CreateCommand();
    }

    public int Login_Id
    {
        get
        {
            _cmd.CommandText = "select * from Ims_Dish_Login where Login_Username=@Login_Username";//去另一个表中查询ID
            _cmd.Parameters.AddWithValue("@Login_Username", this.Login_Username);
            _conn.Open();
            _dr = _cmd.ExecuteReader();
            int a = 0;
            while (_dr.Read())
            {
                a = Convert.ToInt32(_dr["Login_Id"]);
            }
            _conn.Close();
            return a;
        }
    }

}

 

posted @ 2016-01-06 10:04  Franky2015  阅读(221)  评论(0编辑  收藏  举报