日期时间问题 [英] date time problem

查看:116
本文介绍了日期时间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在我的SQL查询中将datetime.now.tostring()作为parMETER传递来检索Todays.的所有交易,但无法检索.
请帮帮我.

我的查询如下:
从bill_details中选择billno,net量,其中date =''"+ DateTime.Now.Tostring()+"'';


i am passing datetime.now.tostring() as parMETER IN MY SQL QUERY for retriving all the transaction of todays.but unable to retrive.
please help me.

my query like:
select billno,net amount from bill_details where date=''" +DateTime.Now.Tostring() + "'';

推荐答案

首先:您没有使用参数,它只是传递到字符串中.

第二:净额"表中的列名称中不能有空格.

第三:Tostring()不存在.它必须是ToString();

该如何完成的是:

(我的演示使用OleDb,但总体上是相同的)

First: You are not using a parameter, it''s just passed into a string.

Second: "net amount" there can be NO spaces in column names within your table.

Third: Tostring() does not exist. It has to be ToString();

How this should be done is:

(My demo uses OleDb but the practice is overall the same)

string sqlQuery = "SELECT billno, net_amount FROM bill_details WHERE date=@Date";

OleDbCommand sqlCommand = new OleDbCommand(sqlQuery, sqlConnection);
sqlCommand.Parameters.Add("@Date", OleDbType.VarChar).Value = DateTime.Now.ToString();

OleDbDataAdapter sqlAdapter = new OleDbDataAdapter(sqlCommand);

DataSet ds = new DataSet();
sqlAdapter.Fill(ds);



现在所有信息都应该在DataSet ds 中.并且可以作为DataSource绑定到DataGridView或以编程方式手动读取.



Now all information should be in DataSet ds. And can be bound as a DataSource to a DataGridView or be read manually progammetically.


这篇关于日期时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆