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. Java基础(41):Java中集合中需要注意的几个要点(关于Collection与Map)

    同步性     Vector是同步的.这个类中的一些方法保证了Vector中的对象是线程安全的.而ArrayList则是异步的,因此ArrayList中的对象并 不是线程安全的.因为同步的要求会影响执 ...

  2. struts自定义拦截器

    第01步:配置web.xml,启动struts框架 <?xml version="1.0" encoding="UTF-8"?> <web-a ...

  3. android复习第一天-----简单的android常识

    前言:要去面试了,这些天花一些事件把android中简单的知识点来串联的复习一下 1,android中的工程结构 src文件夹:存储android文件的源代码 gen文件夹:有工具自动生成,不要去修改 ...

  4. 一个标准的ECharts代码

    <!DOCTYPE html> <head> <meta charset="utf-8"> <title>ECharts</t ...

  5. paper 27 :图像/视觉显著性检测技术发展情况梳理(Saliency Detection、Visual Attention)

    1. 早期C. Koch与S. Ullman的研究工作. 他们提出了非常有影响力的生物启发模型. C. Koch and S. Ullman . Shifts in selective visual ...

  6. 关于 VS 无法转到定义和无法转到使用的问题

    今天提交完代码以后突然发现  咦  怎么F12 .点击右键的方法都不能转到定义了    转到引用 也提示  没有发现   重启VS  还是不行 .去找王晓  他也不清楚(其实我知道 他应该也不清楚  ...

  7. 夺命雷公狗---node.js---11之文件上传

    我们在做文件上传前需要用npm来安装一个插件先, 首先打开项目所在的目录,然后按住shift键然后右键鼠标进入命令行安装formidable 然后开始编写上传的静态页面: <!DOCTYPE h ...

  8. NOIP200407合唱队形+最长上升子序列O(n^2)详解

    合唱队形解题报告 2016-05-12   4:30——6:45 NOIP200407合唱队形 难度级别:A: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:20000 ...

  9. 在TVideoGrabber中如何在预览时设置相机属性

    在使用TVideoGrabber进行预览时,如何设置相机的属性呢?比如曝光.对比度.亮度等. 下面来看一下,如何通过编程来调整这些设置: ——通过指定VideoDevice属性(在VideoDevic ...

  10. netsh修改IP及DNS

    netsh interface ip show addresses  显示当前IP netsh interface ip show dns           显示当前DNS netsh interf ...