| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 803 人关注过本帖
标题:[求助] 选择查询问题
只看楼主 加入收藏
abing293
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2005-12-13
收藏
 问题点数:0 回复次数:7 
[求助] 选择查询问题
图片附件: 游客没有浏览图片的权限,请 登录注册


我如何构造查询语句。
比如,选择网卡卡号、IP地址点查询
这个查询语句我判断不出来
请高手指点

搜索更多相关主题的帖子: 查询 语句 网卡 选择 
2005-12-14 11:28
梦幻情缘
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:769
专家分:20
注 册:2005-4-4
收藏
得分:0 
SQL语句
2005-12-14 11:48
abing293
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2005-12-13
收藏
得分:0 

大哥,你在回答我吗?


活着其实挺累的
2005-12-14 11:52
abing293
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2005-12-13
收藏
得分:0 

这是我昨天晚上作的,自己觉得还是不够精简,查询速度不快。
我想用DATAVIEW应该能更快一些吧。
private void boolchk()
{
string sqlstr="select * from comp where";
if(this.checkBox1.Checked==true)
{
sqlstr+=" fzr='"+this.textBox1.Text.Trim()+"'"+" and ";
}
if(this.checkBox2.Checked==true)
{
sqlstr+=" devicename='"+this.textBox2.Text.Trim()+"' and ";
}
if(this.checkBox3.Checked==true)
{
sqlstr+=" netcode='"+this.textBox3.Text.Trim()+"' and ";
}
if(this.checkBox4.Checked==true)
{
sqlstr+=" ipadd='"+this.textBox4.Text.Trim()+"' and ";
}
if(sqlstr.Length>24)//存在查询条件
{
sqlstr=sqlstr.Substring(0,sqlstr.Length-5);
this.ds.Clear();
this.ds=com.dst(sqlstr,tablename);//com.dst()为数据操作类Com的函数,它返回一个数据集
this.dataGrid1.DataSource=this.ds.Tables[tablename];
}

}

private void button1_Click(object sender, System.EventArgs e)
{
this.boolchk();
}


活着其实挺累的
2005-12-15 10:04
独孤幽灵
Rank: 1
等 级:新手上路
帖 子:115
专家分:0
注 册:2005-11-24
收藏
得分:0 
string sqlstr="select * from comp where";
我想问下

where后面怎么什么没有啊

2005-12-17 15:46
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
this.dataGrid1.DataSource=this.ds.Tables[tablename];

慢是绑定的问题。用普通的显示会快一点。

DataView没用过,一般用的是DataGrid,如果想快。

可以试试用Reader类实现。


PS:楼主的注释写得不够哦,我看了老半天没搞懂你这句

sqlstr=sqlstr.Substring(0,sqlstr.Length-5);
2005-12-18 09:54
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
以下是引用独孤幽灵在2005-12-17 15:46:00的发言:
string sqlstr="select * from comp where";
我想问下

where后面怎么什么没有啊

同志你只看到那行吗?往下看啊!

2005-12-18 09:55
abing293
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2005-12-13
收藏
得分:0 

这是用DATAVIEW实现的,速度相当快,因为查询时不用再连接SQLSERVER。
界面也变了,回帖不会贴图,不好意思。
总体思路是用DATAVIEW的ROWFILTER属性实现查询。
代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace Computer
{
/// <summary>
/// DeviceList 的摘要说明。
/// </summary>
public class DeviceList : System.Windows.Forms.Form
{
private ComC com=new ComC();
private DataTable table;
private DataView dv;
private string tablename="comp";
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.TextBox textBox6;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.DataGrid dataGrid1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public DeviceList()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
this.selectdb(); //把DATAGRID棒定到DATAVIEW
this.datagridbind(); //生成DATAGRID样式
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

private void datagridbind() //生成DATAGRID样式
{
DataGridTableStyle ts=new DataGridTableStyle();
ts.MappingName=this.table.TableName;
ts.AllowSorting=false;
DataGridTextBoxColumn td;
int numcols=this.table.Columns.Count;
for(int i=0;i<numcols;i++)
{
td=new DataGridTextBoxColumn();
td.MappingName=this.table.Columns[i].ColumnName;
td.HeaderText=this.table.Columns[i].ColumnName;
td.NullText="";
ts.GridColumnStyles.Add(td);
}
this.dataGrid1.TableStyles.Add(ts);
}


private void selectdb() //把DATAGRID棒定到DATAVIEW
{
string sqlstr="select devicename as 设备名称,spectype as 设备类型,entertime as 进厂时间,"+
"bm as 使用部门,fzr as 负责人,text as 备注,netcode as 网卡卡号,ipadd as IP地址 from comp order by 使用部门";
this.table=com.dt(sqlstr,this.tablename); //com.dt是数据操作类ComC的成员函数,它返回一

//个DataTable对象。

this.dv=new DataView(this.table);//创建DataView对象dv
this.dataGrid1.DataSource=dv;//把DataGrid绑定到dv上
}

private void button1_Click(object sender, System.EventArgs e)
{
string selstr="";//先把查询条件设置为空字符串
if(this.textBox1.Text.Trim()!="")
selstr+="设备名称='"+this.textBox1.Text.Trim()+"' and ";
if(this.textBox2.Text.Trim()!="")
selstr+="使用部门='"+this.textBox2.Text.Trim()+"' and ";
if(this.textBox3.Text.Trim()!="")
selstr+="负责人='"+this.textBox3.Text.Trim()+"' and ";
if(this.textBox4.Text.Trim()!="")
selstr+="进厂时间='"+this.textBox4.Text.Trim()+"' and ";
if(this.textBox5.Text.Trim()!="")
selstr+="网卡卡号='"+this.textBox5.Text.Trim()+"' and ";
if(this.textBox6.Text.Trim()!="")
selstr+="IP地址='"+this.textBox6.Text.Trim()+"' and ";
if(selstr.Length>0)//存在查询条件
{
selstr=selstr.Substring(0,selstr.Length-5);//这句意思是从selstr中减去最后5个字符
//因为有" and "
}
this.dv.RowFilter=selstr;//把selstr赋给DataView对象dv的RowFilter属性筛选出结果
this.textnull();
}


private void textnull()//清空查询文本框
{
this.textBox6.Text="";
this.textBox5.Text="";
this.textBox4.Text="";
this.textBox3.Text="";
this.textBox2.Text="";
this.textBox1.Text="";
}

private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==(char)13)//检测是否按下了回车键
{
this.button1.Focus();//得到焦点
}
}
}
}

[此贴子已经被作者于2005-12-19 15:10:09编辑过]


活着其实挺累的
2005-12-19 14:24
快速回复:[求助] 选择查询问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.054016 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved