winform中的查询功能

q198708wyp 2011-05-23 02:16:21
起始时间 结束时间 查询 并且在列表里面显示出来 怎们实现,代码
...全文
289 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
sqlquery=@"select * from riqi where date>=COVERT(DATE,'"+BeginTime+"',120) and date<=COVERT(DATE,'"+EndTime+"',120)"
q198708wyp 2011-05-24
  • 打赏
  • 举报
回复
是呀 DateTime sqlquery=@"select * from riqi where date>'"+BeginTime+"' and date<'"+EndTime+"'";
说是类型转换有问题
错误 2 无法将类型“System.DateTime”隐式转换为“string”
错误 1 无法将类型“string”隐式转换为“System.DateTime”
加我QQ可以么 这样方便点。521070107
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 q198708wyp 的回复:]
private void button2_Click(object sender, EventArgs e)

{
string BeginTime=this.dateTimePicker1.Text.ToString();
string EndTime=this.dateTimePicker2.Text.ToString();
string sqlquery=@"s……
[/Quote]
还有,要加改一下查询语句啊,
string sqlquery=@"select * from riqi where date>='"+BeginTime+"' and date<='"+EndTime+"'";
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 q198708wyp 的回复:]
private void button2_Click(object sender, EventArgs e)

{
string BeginTime=this.dateTimePicker1.Text.ToString();
string EndTime=this.dateTimePicker2.Text.ToString();
string sqlquery=@"s……
[/Quote]注意你的查询时间啊,不符合条件的怎么能查出来呢,看看是不是这样
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 q198708wyp 的回复:]
private void button2_Click(object sender, EventArgs e)

{
string BeginTime=this.dateTimePicker1.Text.ToString();
string EndTime=this.dateTimePicker2.Text.ToString();
string sqlquery=@"s……
[/Quote]那显示出来什么呀?
q198708wyp 2011-05-24
  • 打赏
  • 举报
回复

private void button2_Click(object sender, EventArgs e)

{
string BeginTime=this.dateTimePicker1.Text.ToString();
string EndTime=this.dateTimePicker2.Text.ToString();
string sqlquery=@"select * from riqi where date>BeginTime and date<EndTime";

SqlConnection scc=new SqlConnection("Data Source=.;Initial Catalog=login;Integrated Security=True");
SqlCommand scm=new SqlCommand();
scm.CommandType=CommandType.Text;
scm.CommandText=sqlquery;
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=scm;
DataSet ds=new DataSet();
sda.Fill(ds);
dataGridView1.DataSource=ds.Tables[0].DefaultView;

}

能正常运行,但是点击查询按钮的时候不能出来正常的结果。怎么解决呀,八楼,和其他高手帮忙看下。
Bo217 2011-05-23
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 hhqsy 的回复:]
string sqlquery = @"select * from riqi where date>2011-5-12 and date<2011-5-22";

SqlConnection scc = new SqlConnection("Data Source=.;Initial Catalog=log;Integrated Security=True");
SqlCommand ……
[/Quote]
顶一下
rabbitlzx 2011-05-23
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 q198708wyp 的回复:]
不要数据库的查询语句,要button控件下的事件代码。和listbox空间下的代码。
[/Quote]底层就是点了button后 到数据库去查询,然后将返回结果绑定到UI的控件上(listbox)
  • 打赏
  • 举报
回复
string sqlquery = @"select * from riqi where date>2011-5-12 and date<2011-5-22";

SqlConnection scc = new SqlConnection("Data Source=.;Initial Catalog=log;Integrated Security=True");
SqlCommand scm= new SqlCommand();
scm.Connection = scc;
scm.CommandType = CommandType.Text;
scm.CommandText = sqlquery;

SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = scm;
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0].DefaultView;
q198708wyp 2011-05-23
  • 打赏
  • 举报
回复
不要数据库的查询语句,要button控件下的事件代码。和listbox空间下的代码。
xixihaha_2011_098 2011-05-23
  • 打赏
  • 举报
回复
SELECT 列 FROM 表 WHERE 列名 BETWEEN 起始时间 AND 结束时间

SELECT 列 FROM 表 WHERE 时间 > 起始时间 and 时间 < 结束时间

都可以
Arestain 2011-05-23
  • 打赏
  • 举报
回复
SELECT 列
FROM 表
WHERE 列名 BETWEEN 起始时间 AND 结束时间
q198708wyp 2011-05-23
  • 打赏
  • 举报
回复
200102,我是刚刚学起winform 以前是做C++的 麻烦你们说的详细点好么?再次感谢
cjh200102 2011-05-23
  • 打赏
  • 举报
回复
楼上已经写得够详细了。

楼主莫不是自己一点不想写。
q198708wyp 2011-05-23
  • 打赏
  • 举报
回复
我的数据库名字是log 连接的表名字是riqi,查询语句
select * from riqi where date>2011-5-12 and date<2011-5-22.
你把代码 写上,再麻烦一下高手,写好我给你满分
rabbitlzx 2011-05-23
  • 打赏
  • 举报
回复
form上放一个datagridview
查询语句 select <你要查询的> from xxx when 时间 > 起始时间 and 时间 < 结束时间
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = 连接对象;
cmd.CommandType = CommandType.Text;
cmd.CommandText = 查询语句;

然后将查询结果存到DataTable中,
DataTable dt = new DataTable();
SqlDataAdapter dapt = new SqlDataAdapter(cmd);
dapt.Fill(dt);

关联datagridview和查询结果 datagridview1.DataSource = dt;

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧