一、

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. The Accomodation of Students HDU - 2444(判断二分图 + 二分匹配)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  2. 从web启动winform程序

    最近有个客户提出想从网站上启动一个客户端的程序,研究了下,实现方法如下: 1. 注入注册表 try                {                    string appPath ...

  3. 【bzoj3160】 万径人踪灭

    http://www.lydsy.com/JudgeOnline/problem.php?id=3160 (题目链接) 题意 给定一个由'a'和'b'构成的字符串,求不连续回文子序列的个数. Solu ...

  4. 前端学习 -- Css -- 否定伪类

    语法::not(.选择器) 作用:可以从已选中的元素中剔除出某些元素. <!DOCTYPE html> <html> <head> <meta charset ...

  5. C++时间标准库时间time

    转自:http://www.cnblogs.com/yukaizhao/archive/2011/04/29/cpp_time_system_time.html (玉开) C++标准库中的时间需要引用 ...

  6. kubespray 一键安装k8s集群

    1. clone代码 git clone https://github.com/kubernetes-incubator/kubespray.git 2. 添加inventory/inventory ...

  7. bzoj千题计划205:bzoj1966: [Ahoi2005]VIRUS 病毒检测

    http://www.lydsy.com/JudgeOnline/problem.php?id=1966 f[i][j] 表示s的前i个和t的前j个是否匹配 转移看代码 注意初始化: f[0][0]= ...

  8. bzoj千题计划180:bzoj4411: [Usaco2016 Feb]Load balancing

    http://www.lydsy.com/JudgeOnline/problem.php?id=4411 用树状数组维护扫描线 一个树状数组维护扫描线之上的y<=i点,另一个维护扫描线之下y&l ...

  9. XHR工厂的实现

    ajax这种常见的开发模式已经遍布我们日常的开发之中了,ajax本质还是采用一种轮询的模式,就是隔一段时间去发送一次http请求,获取数据,然后显示在页面之上,当然,ajax比起新兴的WebScoke ...

  10. ASP.NET生成二维码

    下面使用ThoughtWorks.QRCode.dll这个类库,实现生成二维码 使用时需要增加:下面三个命名空间 using ThoughtWorks.QRCode.Codec; using Thou ...