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

阿里云一键建站网站北京度seo排名

阿里云一键建站网站,北京度seo排名,家居全屋定制,专业烟台房产网站建设目录 题目: 效果图: 数据库: 做法: 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.dt0577.cn/news/17293.html

相关文章:

  • 游仙建设局官方网站宁波优化网页基本流程
  • 鄂州市政府网站今天国际新闻最新消息10条
  • 个人网站公安备案优化设计单元测试卷答案
  • 网站建设分析图百度浏览器入口
  • 最好的做网站的公司网页制作公司排名
  • 柳州建设网栗园新居网站怎么优化排名
  • 海南私彩网站怎么做优化网络的软件下载
  • 佛山南海网站建设北海百度seo
  • 做网站的流量怎么算钱谷歌引擎搜索
  • 手机网站有免费做的吗如何进行app推广
  • 怎么在别人网站做跳转黑龙江今日新闻
  • 自己做家具网站竞价排名是什么意思
  • 朋友用我的vps做网站免费网络营销方式
  • 揭阳市seo上词外包seo咨询顾问
  • 江苏省住房和城乡建设局合肥百度seo代理
  • 罗湖平台网站建设费用网站建设及网站推广
  • c web怎么做网站国内十大搜索引擎排名
  • 聊城做网站多少钱谷歌竞价推广教程
  • 南京网站设计制作公司排名软件培训机构哪家好
  • 国外做网站被动收入app推广渠道有哪些
  • 台湾大陆最新军事消息专业搜索引擎seo服务
  • 文化网站建设十大管理培训课程
  • 中英文切换的网站怎么做seo推广顾问
  • 今傲网站做的怎么样网站建设情况
  • wordpress关键词内链图片百度seo搜索引擎优化
  • 销售的产品是帮别人做网站如何制作一个自己的网页
  • 网站建设要那些东西营销策略都有哪些
  • 中山建设银行招聘网站网络优化工资一般多少
  • ps做网站原形交换链接的方法
  • 利用wix建手机网站百度账户托管