一、

1、Car表数据查出显示
2、请输入要查的汽车名称:
     请输入要查的汽车油耗:
     请输入要查的汽车马力:

        static void Main(string[] args)
{
SqlConnection Car = new SqlConnection("server=.;database=bosamvs;user=sa;pwd=123456;");
#region 1、Car表数据查出显示
SqlCommand cmd = Car.CreateCommand();
cmd.CommandText = "select code,name,oil,powers,exhaust,price from car";
Car.Open();
SqlDataReader table = cmd.ExecuteReader();
if (table.HasRows)
{
while (table.Read())
{
Console.WriteLine("编号:{0}\t名字:{1}\t油耗:{2}\t马力:{3}\t排量:{4}\t价格:{5}", table["code"], table["name"], table["oil"], table["powers"], table["exhaust"], table["price"]);
}
}
Car.Close();
#endregion
Console.ReadLine();
Console.Clear();
#region 2、请输入要查的汽车名称,油耗,马力:
while (true)
{
Console.Write("请输入查询的汽车名称:");
string name = Console.ReadLine();
Console.Write("请输入查询的汽车油耗:");
string oil = Console.ReadLine();
Console.Write("请输入查询的汽车马力:");
string powers = Console.ReadLine();
#region 输入全部为空
if (name == "" && oil == "" && powers == "")
{
Console.WriteLine("***********************全部信息***********************");
SqlCommand cmd0 = Car.CreateCommand();
cmd0.CommandText = "select*from car";
try
{
Car.Open();
SqlDataReader table0 = cmd0.ExecuteReader();
if (table0.HasRows)
{
while (table0.Read())
{
Console.WriteLine("ID:{0}\t编号:{1}\t名字:{2}\t系列:{3}\t出厂日期:{4}\t油耗:{5}\t马力:{6}\t排量:{7}\t价格:{8}", table0["ids"], table0["code"], table0["name"], table0["brand"], table0["time"], table0["oil"], table0["powers"], table0["exhaust"], table0["price"]);
}
}
Car.Close();
}
catch
{
Console.WriteLine("查询出错!");
}
}
#endregion
else
{
#region 输入车名不为空
if (name != "")
{
#region 输入油耗为空
if (oil == "" && powers != "")
{
int powers1 = Convert.ToInt32(powers);
SqlCommand cmd1 = Car.CreateCommand();
cmd1.CommandText = "select code,name,oil,powers,exhaust,price from car where name like '%" + name + "%' or powers = " + powers1;
try
{
Car.Open();
SqlDataReader table1 = cmd1.ExecuteReader();
if (table1.HasRows)
{
while (table1.Read())
{
Console.WriteLine("编号:{0}\t名字:{1}\t油耗:{2}\t马力:{3}\t排量:{4}\t价格:{5}\t", table1["code"], table1["name"], table1["oil"], table1["powers"], table1["exhaust"], table1["price"]);
}
}
Car.Close();
}
catch
{
Console.WriteLine("查询出错!");
}
}
#endregion
#region 输入马力为空
else if (oil != "" && powers == "")
{
decimal oil1 = Convert.ToDecimal(oil);
SqlCommand cmd2 = Car.CreateCommand();
cmd2.CommandText = "select code,name,oil,powers,exhaust,price from car where name like '%" + name + "%' or oil = " + oil1;
try
{
Car.Open();
SqlDataReader table2 = cmd2.ExecuteReader();
if (table2.HasRows)
{
while (table2.Read())
{
Console.WriteLine("编号:{0}\t名字:{1}\t油耗:{2}\t马力:{3}\t排量:{4}\t价格:{5}\t", table2["code"], table2["name"], table2["oil"], table2["powers"], table2["exhaust"], table2["price"]);
}
}
Car.Close();
}
catch
{
Console.WriteLine("查询出错!");
}
}
#endregion
#region 输入油耗和马力都为空
else if (oil == "" && powers == "")
{
SqlCommand cmd3 = Car.CreateCommand();
cmd3.CommandText = "select code,name,oil,powers,exhaust,price from car where name like '%" + name + "%'";
try
{
Car.Open();
SqlDataReader table3 = cmd3.ExecuteReader();
if (table3.HasRows)
{
while (table3.Read())
{
Console.WriteLine("编号:{0}\t名字:{1}\t油耗:{2}\t马力:{3}\t排量:{4}\t价格:{5}\t", table3["code"], table3["name"], table3["oil"], table3["powers"], table3["exhaust"], table3["price"]);
}
}
Car.Close();
}
catch
{
Console.WriteLine("查询出错!");
}
}
#endregion
#region 全部输入
else if (oil != "" && powers != "")
{
decimal oil1 = Convert.ToDecimal(oil);
int powers1 = Convert.ToInt32(powers);
SqlCommand cmd4 = Car.CreateCommand();
cmd4.CommandText = "select code,name,oil,powers,exhaust,price from car where name like '%" + name + "%' or oil = " + oil1 + " or powers = " + powers1;
try
{
Car.Open();
SqlDataReader table4 = cmd4.ExecuteReader();
if (table4.HasRows)
{
while (table4.Read())
{
Console.WriteLine("编号:{0}\t名字:{1}\t油耗:{2}\t马力:{3}\t排量:{4}\t价格:{5}\t", table4["code"], table4["name"], table4["oil"], table4["powers"], table4["exhaust"], table4["price"]);
}
}
Car.Close();
}
catch
{
Console.WriteLine("查询出错!");
}
}
#endregion
}
#endregion
#region 输入油耗不为空
else if (oil != "")
{
#region 输入车名为空
if (name == "" && powers != "")
{
decimal oil2 = Convert.ToDecimal(oil);
int powers2 = Convert.ToInt32(powers);
SqlCommand cmd5 = Car.CreateCommand();
cmd5.CommandText = "select code,name,oil,powers,exhaust,price from car where oil=" + oil2 + " or powers=" + powers2;
try
{
Car.Open();
SqlDataReader table5 = cmd5.ExecuteReader();
if (table5.HasRows)
{
while (table5.Read())
{
Console.WriteLine("编号:{0}\t名字:{1}\t油耗:{2}\t马力:{3}\t排量:{4}\t价格:{5}\t", table5["code"], table5["name"], table5["oil"], table5["powers"], table5["exhaust"], table5["price"]);
}
}
Car.Close();
}
catch
{
Console.WriteLine("查询出错!");
}
}
#endregion
#region 输入马力为空
else if (name != "" && powers == "")
{
decimal oil2 = Convert.ToDecimal(oil);
SqlCommand cmd6 = Car.CreateCommand();
cmd6.CommandText = "select code,name,oil,powers,exhaust,price from car where name like '%" + name + "%' or oil=" + oil2;
try
{
Car.Open();
SqlDataReader table6 = cmd6.ExecuteReader();
if (table6.HasRows)
{
while (table6.Read())
{
Console.WriteLine("编号:{0}\t名字:{1}\t油耗:{2}\t马力:{3}\t排量:{4}\t价格:{5}\t", table6["code"], table6["name"], table6["oil"], table6["powers"], table6["exhaust"], table6["price"]);
}
}
Car.Close();
}
catch
{
Console.WriteLine("查询出错!");
}
}
#endregion
#region 输入车名和马力都为空
else if (name == "" && powers == "")
{
decimal oil2 = Convert.ToDecimal(oil);
SqlCommand cmd7 = Car.CreateCommand();
cmd7.CommandText = "select code,name,oil,powers,exhaust,price from car where oil=" + oil2;
Car.Open();
SqlDataReader table7 = cmd7.ExecuteReader();
if (table7.HasRows)
{
while (table7.Read())
{
Console.WriteLine("编号:{0}\t名字:{1}\t油耗:{2}\t马力:{3}\t排量:{4}\t价格:{5}\t", table7["code"], table7["name"], table7["oil"], table7["powers"], table7["exhaust"], table7["price"]);
}
}
Car.Close();
}
#endregion
}
#endregion
#region 输入马力不为空
else if (powers != "")
{
#region 输入车名为空
if (name == "" && oil != "")
{
decimal oil2 = Convert.ToDecimal(oil);
int powers2 = Convert.ToInt32(powers);
SqlCommand cmd8 = Car.CreateCommand();
cmd8.CommandText = "select code,name,oil,powers,exhaust,price from car where oil=" + oil2 + " or powers=" + powers2;
try
{
Car.Open();
SqlDataReader table8 = cmd8.ExecuteReader();
if (table8.HasRows)
{
while (table8.Read())
{
Console.WriteLine("编号:{0}\t名字:{1}\t油耗:{2}\t马力:{3}\t排量:{4}\t价格:{5}\t", table8["code"], table8["name"], table8["oil"], table8["powers"], table8["exhaust"], table8["price"]);
}
}
Car.Close();
}
catch
{
Console.WriteLine("查询出错!");
}
}
#endregion
#region 输入油耗为空
else if (name != "" && oil == "")
{
int powers2 = Convert.ToInt32(powers);
SqlCommand cmd9 = Car.CreateCommand();
cmd9.CommandText = "select code,name,oil,powers,exhaust,price from car where name like '%" + name + "%' or powers=" + powers2;
try
{
Car.Open();
SqlDataReader table9 = cmd9.ExecuteReader();
if (table9.HasRows)
{
while (table9.Read())
{
Console.WriteLine("编号:{0}\t名字:{1}\t油耗:{2}\t马力:{3}\t排量:{4}\t价格:{5}\t", table9["code"], table9["name"], table9["oil"], table9["powers"], table9["exhaust"], table9["price"]);
}
}
Car.Close();
}
catch
{
Console.WriteLine("查询出错!");
}
}
#endregion
#region 输入车名和油耗都为空
else if (name == "" && oil == "")
{
int powers2 = Convert.ToInt32(powers);
SqlCommand cmd10 = Car.CreateCommand();
cmd10.CommandText = "select code,name,oil,powers,exhaust,price from car where powers=" + powers2;
try
{
Car.Open();
SqlDataReader table10 = cmd10.ExecuteReader();
if (table10.HasRows)
{
while (table10.Read())
{
Console.WriteLine("编号:{0}\t名字:{1}\t油耗:{2}\t马力:{3}\t排量:{4}\t价格:{5}\t", table10["code"], table10["name"], table10["oil"], table10["powers"], table10["exhaust"], table10["price"]);
}
}
Car.Close();
}
catch
{
Console.WriteLine("查询出错!");
}
}
#endregion
}
#endregion
}
}
#endregion
Console.ReadLine();

ADO.Net练习1的更多相关文章

  1. ADO.NET对象的详解

    1. Connection 类 和数据库交互,必须连接它.连接帮助指明数据库服务器.数据库名字.用户名.密码,和连接数据库所需要的其它参数.Connection对象会被Command对象使用,这样就能 ...

  2. WebForm获取GET或者POST参数到实体的转换,ADO.NET数据集自动转换实体

    最近在修改维护以前的webform项目(维护别人开发的.....)整个aspx没有用到任何的控件,这个我也比较喜欢不用控件所以在提交信息的时候需要自己手动的去Request.QueryString[] ...

  3. ADO.NET编程之美----数据访问方式(面向连接与面向无连接)

    最近,在学习ADO.NET时,其中提到了数据访问方式:面向连接与面向无连接.于是,百度了一下,发现并没有很好的资料,然而,在学校图书馆中发现一本好书(<ASP.NET MVC5 网站开发之美&g ...

  4. ADO.NET一小记-select top 参数问题

    异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html 最近使用ADO.NET的时候,发现select top @count xxxx 不 ...

  5. .NET基础拾遗(6)ADO.NET与数据库开发基础

    Index : (1)类型语法.内存管理和垃圾回收基础 (2)面向对象的实现和异常的处理 (3)字符串.集合与流 (4)委托.事件.反射与特性 (5)多线程开发基础 (6)ADO.NET与数据库开发基 ...

  6. 升讯威ADO.NET增强组件(源码):送给喜欢原生ADO.NET的你

    目前我们所接触到的许多项目开发,大多数都应用了 ORM 技术来实现与数据库的交互,ORM 虽然有诸多好处,但是在实际工作中,特别是在大型项目开发中,容易发现 ORM 存在一些缺点,在复杂场景下,反而容 ...

  7. ADO.NET Entity Framework 在哪些场景下使用?

    在知乎回答了下,顺手转回来. Enity Framework已经是.NET下最主要的ORM了.而ORM从一个Mapping的概念开始,到现在已经得到了一定的升华,特别是EF等对ORM框架面向对象能力的 ...

  8. ADO.NET 核心对象简介

    ADO.NET是.NET中一组用于和数据源进行交互的面向对象类库,提供了数据访问的高层接口. ADO.NOT类库在System.Data命名空间内,根据我们访问的不同数据库选择命名空间,System. ...

  9. ODBC、OLE DB、 ADO的区别

    转自:http://blog.csdn.net/yinjingjing198808/article/details/7665577 一.ODBC ODBC的由来 1992年Microsoft和Syba ...

  10. LINQ to SQL语句(19)之ADO.NET与LINQ to SQL

    它基于由 ADO.NET 提供程序模型提供的服务.因此,我们可以将 LINQ to SQL 代码与现有的 ADO.Net 应用程序混合在一起,将当前 ADO.NET 解决方案迁移到 LINQ to S ...

随机推荐

  1. Python之路:Python操作 RabbitMQ、Redis、Memcache、SQLAlchemy

    Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...

  2. pgm3

    这部分主要讨论了一些概念性的东西.一个是常用的 local probabilistic models,一个是如何用 template-based representation. 这部分主要是一些概念, ...

  3. 知乎网的CSS命名规律研究

    笔者是一名Java程序员,前端css和图片本不是我的工作,亦不是我的强项.但很多时候,公司并没有合适的美工,只有自己动手.一般的css技术,倒是没有问题,定位,盒子,浮动,布局等等,都能做.但每每完成 ...

  4. BZOJ3434 WC2014时空穿梭(莫比乌斯反演)

    考虑枚举相邻点距离差的比例.显然应使比例值gcd为1以保证不重复统计.确定比例之后,各维坐标的方案数就可以分开考虑.设比例之和为k,则若坐标上限为m,该维坐标取值方案数即为Σm-ki (i=1~⌊m/ ...

  5. 基于Python的轻量级RPC的实现

    一 什么是RPC(Remote Procedure Call)远程过程调用 二 RPC or Resful 三 重复造轮子之手撸自己的RPC(基于python语言)

  6. 如何用React, Webcam和JS Barcode SDK创建Web扫码App

    这篇文章分享下如何结合React Webcam和Dynamsoft JavaScript Barcode SDK来创建Web扫码App. Web实时扫码 从GitHub上下载react-webcam. ...

  7. diyiti.cpp

    diyiti.cpp/c/pas diyiti.in diyiti.out 2s/256MB 给定两个01串,S,T(下标从0开始). 支持如下3种操作: 1. 修改S第i位的字符,即0->1, ...

  8. POJ 2135 Farm Tour (网络流,最小费用最大流)

    POJ 2135 Farm Tour (网络流,最小费用最大流) Description When FJ's friends visit him on the farm, he likes to sh ...

  9. SQL中的全局变量和局部变量(@@/@)

    在SQL中,我们常常使用临时表来存储临时结果,对于结果是一个集合的情况,这种方法非常实用,但当结果仅仅是一个数据或者是几个数据时,还要去建一个表,显得就比较麻烦,另外,当一个SQL语句中的某些元素经常 ...

  10. centos安装lrzsz

    yum -y install lrzsz 使用rz打开上传框