create database guoji--建立数据库
go
use guoji
go
create table xinxi--建立表一
(
name varchar(20),
minzu varchar(20)
)
insert into xinxi values('lisi','');
insert into xinxi values('wangwu','');
insert into xinxi values('zhaoliu','');
select * from xinxi
go create table minz--建立表二
(
mcode varchar(20),
mname varchar(20)
)
insert into minz values('','汉族');
insert into minz values('','满族');
insert into minz values('','藏族');
go
select * from minz

要求:查询表一,民族部分用汉族展现出来!!!

//进行xinxi表的实体化
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace biao.App_Code
{
public class xinxi
{
private string _name;
public string name
{
get { return _name; }
set { _name = value; }
} private string _minzu;
public string minzu//用这个接受数据
{
get { return _minzu; }
set { _minzu = value; }
}
public string minzustr//用这个输出数据
{
get
{
minzdata n = new minzdata();
string m = n.mname(_minzu);
return m;
}
}
//进行xinxi表的数据数据访问类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient; namespace biao.App_Code
{
public class xinxidata
{
SqlConnection cnn = null;
SqlCommand cmd = null;
public xinxidata()
{
cnn = new SqlConnection("server=.;database=guoji;user=sa;pwd=123");
cmd = cnn.CreateCommand();
} public List<xinxi> select()//查询全部信息,把信息放到集合里
{
xinxi x = null;
List<xinxi> list = new List<xinxi>();
cmd.CommandText = "select * from xinxi";
cnn.Open();
SqlDataReader ss = cmd.ExecuteReader();
if (ss.HasRows)
{ while (ss.Read())
{
x = new xinxi();
x.name = ss["name"].ToString();
x.minzu = ss["minzu"].ToString();
list.Add(x);
}
}
else
{
Console.WriteLine("此表为空,没有数据!");
}
cnn.Close();
return list;
}
//minz表的实体化
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace biao.App_Code
{
public class minz
{
private string _mcode;
public string mcode
{
get { return _mcode; }
set { _mcode = value; }
} private string _mname;
public string mname
{
get { return _mname; }
set { _mname = value; }
} }
}
//minz表的数据访问类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient; namespace biao.App_Code
{
public class minzdata
{
SqlConnection cnn = null;
SqlCommand cmd = null;
public minzdata()
{
cnn = new SqlConnection("server=.;database=guoji;user=sa;pwd=123");
cmd = cnn.CreateCommand();
} public string mname(string code)//根据编号查姓名
{ string a = "<无>";
cmd.CommandText = "select * from minz where mcode=@a";
cmd.Parameters.Clear();
cmd.Parameters.Add("@a",code);
cnn.Open();
SqlDataReader ss = cmd.ExecuteReader();
if (ss.HasRows)//是否有这个数据
{
ss.Read();
a = ss[].ToString(); }
else
{
Console.WriteLine("数据表为空");
} cnn.Close(); return a;
} }
}
//在program类的主函数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using biao.App_Code; namespace biao
{
class Program
{
static void Main(string[] args)
{
xinxidata a = new xinxidata();
List<xinxi> list = a.select();
foreach (xinxi b in list)//遍历集合查询全部内容
{
Console.WriteLine(b.name + " " + b.minzustr);//用b.minzustr输出语句
} Console.ReadLine();
}
}
}

完!!

ADO SQL属性扩展————多表组合成新的更完整的表的更多相关文章

  1. iNeuOS工业互联平台,图表与数据点组合成新组件,进行项目复用

    目       录 1.      概述... 1 2.      演示信息... 2 3.      应用过程... 2 1.   概述 针对有些行业的数据已经形成了标准化的建模或者有些公司专注于某 ...

  2. ADO.Net属性扩展

    属性扩展 大体意思:有外键关系时将代号化信息处理成原始文字 如:Info表中的民族列显示的是民族代号处理成Nation表中的民族名称 需要在Info类里面扩展一个显示nation名称的属性 using ...

  3. ado.net 属性扩展 综合练习

    实现数据查询,添加,删除,修改各项功能 业务逻辑层: using System; using System.Collections.Generic; using System.Linq; using ...

  4. 【2017-04-21】Ado.Nte属性扩展

    通过对数据库表的封装,对该表的属性进行扩展. 1.例如:表中的性别是bool类,要实现显示给用户看的为“男.女” 2.通过表中的生日datetime类,来实现显示给用户看的年月日,自动计算年龄. 3. ...

  5. 如何将数组2对象中的属性push进数组1的对象中去,组合成新的数组

  6. F# 可以把几个函数组合成新函数

    C#能做的,F#基本都能做,但F#能做的,C#未必能做. F#中的函数可以把几个函数组合起来使用.下面的例子是把由 function1 和 function2 这两个函数通过运算符“>>” ...

  7. js循环匹配组合成新对象或js循环组合新数据

    var Arry=[ {name: "vehicleTravelLicenseCopyBack", id: "a1"}, {name: "vehicl ...

  8. 如何快速将一个list<a>集合中的部分字段值组合成新的的list<b>部分*

    有的时候,我们只需要从老数据中拿一部分数据作为新的绑定数据,比如说绑定下拉框的时候需要构造我们需要的数据格式可以采用以下的方法 public class SelectDataViewModel { p ...

  9. SQL语句 在一个表中插入新字段

    SQL语句 在一个表中插入新字段: alter table 表名 add 字段名 字段类型 例: alter table OpenCourses add Audio varchar(50)alter ...

随机推荐

  1. Python学习总结12:sys模块

    sys模块常用来处理Python运行时配置以及资源,从而可以与前当程序之外的系统环境交互. 1. 导入及函数查看 >>> import sys #导入sys模块 >>&g ...

  2. 。。。无语的Eclipse+Tomact。。。

    晕哦,今天又被Eclipse给骗了,今天部署了一个SSH的环境,搞了半天,JAR包是通过BuildPath导入进去的,怎么搞都报错,说是找不到Spring-Web的一个Jar包,差点没有把我给弄死.. ...

  3. Android -- 背景虚化

    1,在项目中我们常有这样的需求,就是在个人中心的时候,当用户登录后,要显示用户登陆后的头像,然后背景是用户头像的虚化 ,接下来就来实现一下这个功能,先看一下效果 2,实现起来也挺简单的,没什么难度 , ...

  4. Java实现找出数组中重复次数最多的元素以及个数

    /**数组中元素重复最多的数 * @param array * @author shaobn * @param array */ public static void getMethod_4(int[ ...

  5. SQL语句:find_in_set的使用方法

    如果我们有一张表: 里面有的信息如下: 我们需要查找出friends字段里面包含11的值. 我们传统的方法是: %"; 但是这样查到的结果2条的,不大符合我们的需求,如下所示: 我们只想查找 ...

  6. Logic Bist Arch

    一般现在多用的都是offline BIST的架构,可以分为4大类: 1)those assume no special structure to the circuit under test; 2)t ...

  7. Python 入門語法和類型(转载学习)

    http://www.cnblogs.com/mcdou/archive/2011/08/02/2125016.html Python的设计目标之一是让源代码具备高度的可读性.它设计时尽量使用其它语言 ...

  8. PAT乙级 1002. 写出这个数 (20)

    1002. 写出这个数 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 读入一个自然数n,计算其各位数字 ...

  9. beta-1阶段各组员的贡献分分配

    小组名称:nice! 小组成员:李权 于淼 刘芳芳 韩媛媛 宫丽君 项目内容:约跑app 分数分配规则 个人贡献分=基本贡献分*0.2+特殊贡献分*0.3+个人代码贡献量*0.5 其中 基本贡献分,特 ...

  10. Windows cmd 颜色,字体,color font set up

    windows的cmds默认的字体很丑,丑的不认直视,『如花』一般. 但是总有用到的时候 这是我有优化的一种结果,怎么来弄呢 要字体颜色漂亮,先要在注册表的Console中注册你要使用的字体,这个至关 ...