当前位置: 首页 > news >正文

南岸集团网站建设南昌市建设工程质量监督站网站

南岸集团网站建设,南昌市建设工程质量监督站网站,哈尔滨网站优化页面,做网站苏州目录 题目: 效果图: 数据库: 做法: combobox值更新 查询按钮功能(非空验证,查询数据) datagirdview设置 全部代码: DBHelper类 From1主窗体代码 题目: 效果图&#…

目录

题目:

 效果图:

 数据库:

做法:

combobox值更新

 查询按钮功能(非空验证,查询数据)

datagirdview设置

全部代码: 

 DBHelper类

 From1主窗体代码


题目:

 

 

 效果图:

                                               

 数据库:

 

 

做法:

combobox值更新

当comboBox1.text的文本为排量和售价时,显示两个文本框,其他情况仅显示一个文本框。每次选择完节点后两个文本框的值设置为空

 

 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e){if (comboBox1.Text=="品牌"||comboBox1.Text == "型号"|| comboBox1.Text == "变速箱"){textBox1.Text= "";textBox2.Text = "";label4.Hide();textBox2.Hide();}if (comboBox1.Text == "排量"|| comboBox1.Text == "售价"){textBox1.Text = "";textBox2.Text = "";label4.Show();textBox2.Show();}}

 查询按钮功能(非空验证,查询数据)

非空验证:当点击查询按钮时,查询种类combobox不能为空,当combobox有值时,如果查询种类为品牌、型号、变速箱则第一个不能为空,如果查询种类为排量、售价时两个文本框都不能为空

 private void button1_Click(object sender, EventArgs e){//comboBox非空验证if (comboBox1.Text==""){MessageBox.Show("请选择查询种类!");return;}//textbox非空验证if (comboBox1.Text=="排量"|| comboBox1.Text == "售价" ){if (textBox1.Text==""||textBox2.Text==""){MessageBox.Show("查询条件输入不完整!");return;}}if (comboBox1.Text == "品牌" || comboBox1.Text == "型号" || comboBox1.Text == "变速箱"){if (textBox1.Text == "" ){MessageBox.Show("查询条件输入不完整!");return;}}

查询数据: 

查询种类为品牌、型号、变速箱时,定义字符串用来存数据库中的对应列名,列名有了后根据textbox进行模糊查询并显示就好了。

查询种类为排量、售价时,定义字符串用来存数据库中的对应列名,列名有了后根据textbox1和textbox2进行between and区间查询就好了。

因为排量时小数,定义变量直接就用的double类型:

double qi = Convert.ToDouble(textBox1.Text);

 double z = Convert.ToDouble(textBox2.Text);

//如果是这三种情况,拿到选项对应数据库中的列进行查询if (comboBox1.Text == "品牌" || comboBox1.Text == "型号" || comboBox1.Text == "变速箱") {string x = "";if (comboBox1.Text=="品牌"){x = "brand";}else if (comboBox1.Text == "型号"){x = "type";}else{x = "gearbox";}string sql = string.Format("select * from tb_car where {0} like '%{1}%'",x,textBox1.Text);this.dataGridView1.DataSource= DBHelper.ds(sql).Tables[0];}//如果是这两种情况,拿到选项对应数据库中的列进行查询else if (comboBox1.Text == "排量" || comboBox1.Text == "售价"){string tiaoJian = "";if (comboBox1.Text=="排量"){tiaoJian = "discharge";}else{tiaoJian = "price";}double qi = Convert.ToDouble(textBox1.Text);double z = Convert.ToDouble(textBox2.Text);string sql = string.Format("select * from tb_car where {0} between {1} and {2}", tiaoJian,qi,z);this.dataGridView1.DataSource = DBHelper.ds(sql).Tables[0];}else{string sql= "select * from tb_car";this.dataGridView1.DataSource=  DBHelper.ds(sql).Tables[0];}

datagirdview设置

 

首先设置datagridview的这三个属性

    1. AutoSizeColumsMode = Fill 设置每列单元格宽度平铺

    1. RowHeadersVisible = False 取消列表最左侧列显示

    1. SelectionMode = FullRowSelect 设置单元格选中模式为整行选中

 

全部代码: 

 DBHelper类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace WindowsFormsApp1
{internal class DBHelper{public static string connstr = "server=.;database=CarDBj;uid=sa;pwd=123456";public static SqlConnection conn = null;public static void init() {if (conn==null){conn=new SqlConnection(connstr);}conn.Close();conn.Open();}public static bool noqery(string sql) { init();SqlCommand cod=new SqlCommand(sql,conn);if (cod.ExecuteNonQuery()>0){conn.Close();return true;}else{conn.Close();return false;}}public static DataSet ds(string sql) {init();DataSet ds = new DataSet();SqlDataAdapter t = new SqlDataAdapter(sql ,conn);t.Fill(ds);conn.Close();return ds;}}
}

 From1主窗体代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace WindowsFormsApp1
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){string sql = "select * from  tb_car";this.dataGridView1.DataSource=   DBHelper.ds(sql).Tables[0];label4.Hide();textBox2.Hide();}private void comboBox1_SelectedIndexChanged(object sender, EventArgs e){if (comboBox1.Text=="品牌"||comboBox1.Text == "型号"|| comboBox1.Text == "变速箱"){textBox1.Text= "";textBox2.Text = "";label4.Hide();textBox2.Hide();}if (comboBox1.Text == "排量"|| comboBox1.Text == "售价"){textBox1.Text = "";textBox2.Text = "";label4.Show();textBox2.Show();}}private void button1_Click(object sender, EventArgs e){//comboBox非空验证if (comboBox1.Text==""){MessageBox.Show("请选择查询种类!");return;}//textbox非空验证if (comboBox1.Text=="排量"|| comboBox1.Text == "售价" ){if (textBox1.Text==""||textBox2.Text==""){MessageBox.Show("查询条件输入不完整!");return;}}if (comboBox1.Text == "品牌" || comboBox1.Text == "型号" || comboBox1.Text == "变速箱"){if (textBox1.Text == "" ){MessageBox.Show("查询条件输入不完整!");return;}}//如果是这三种情况,拿到选项对应数据库中的列进行查询if (comboBox1.Text == "品牌" || comboBox1.Text == "型号" || comboBox1.Text == "变速箱") {string x = "";if (comboBox1.Text=="品牌"){x = "brand";}else if (comboBox1.Text == "型号"){x = "type";}else{x = "gearbox";}string sql = string.Format("select * from tb_car where {0} like '%{1}%'",x,textBox1.Text);this.dataGridView1.DataSource= DBHelper.ds(sql).Tables[0];}//如果是这两种情况,拿到选项对应数据库中的列进行查询else if (comboBox1.Text == "排量" || comboBox1.Text == "售价"){string tiaoJian = "";if (comboBox1.Text=="排量"){tiaoJian = "discharge";}else{tiaoJian = "price";}double qi = Convert.ToDouble(textBox1.Text);double z = Convert.ToDouble(textBox2.Text);string sql = string.Format("select * from tb_car where {0} between {1} and {2}", tiaoJian,qi,z);this.dataGridView1.DataSource = DBHelper.ds(sql).Tables[0];}else{string sql= "select * from tb_car";this.dataGridView1.DataSource=  DBHelper.ds(sql).Tables[0];}}}
}
http://www.15wanjia.com/news/162411.html

相关文章:

  • 福建省城乡建设官方网站设计师招聘
  • 网站开发交什么税和田地seo
  • 备案网站电子照幕布wordpress无法将上传的文件移动至
  • 自己开发微网站网上哪个网站教做西点
  • 网站整套模板wordpress 端口映射
  • 博白建设局网站下载建设银行官方网站下载
  • 摄影的网站设计特点wordpress中英文菜单
  • 网站模板使用教程黄冈网站建设报价表
  • 黑龙江能源建设网站网店代运营一年的费用是多少
  • 微信小程序 购物网站开发架构图在什么网站可以做
  • 涡阳网站优化wordpress 医院主题
  • 如何用微信做网站全国市场主体登记注册服务网
  • 网站建设运营的灵魂是什么重庆最新宣传片
  • wordpress生产静态页面php网站开发优化方案
  • 网站怎么做实名认证php做网站示例
  • 区块链 做网站成品网站1688入口网页版怎样
  • 建网站需要哪些网站开发体会范文
  • 如何面试网站开发网站建设制作报价方案
  • 仪器仪表行业网站建设论坛类型的网站怎么做
  • 网站地图分析工具长安网站建设好吗
  • 网站开发实训课程的总结建筑搜索网站
  • 汉阳网站推广公司成都网站设计优选柚v米科技
  • 分享惠网站怎么做惠安网站建设公司
  • 建设网站的请示网站的结构与布局优化设计
  • 做网站设计的有些什么职位广州代做公司网站
  • wordpress ses插件网络推广优化seo
  • 厦门上网站设计建设常见的搜索引擎有哪些
  • 宜春做网站的公司哪家好wordpress页脚怎么修改
  • 永定门网站建设长沙h5建站
  • 河南五建建设集团有限公司网站济南 制作网站 公司吗