Ado.net 类扩展属性

、要扩展的类名字一样,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 = ;
while (_dr.Read())
{
a = Convert.ToInt32(_dr["Login_Id"]);
}
_conn.Close();
return a;
}
} }
上一篇:取消设置透明状态栏,使 ContentView 内容不再覆盖状态栏


下一篇:python中一个py文件如何调用其他py文件中的类和函数