如何使用where子句从数据库中读取多个值 [英] How to read multiple values from database using where clause
本文介绍了如何使用where子句从数据库中读取多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨......
如何在where子句中使用相同的列2值读取表值,是否可以?
正在根据日期值读取数据,但是日期是单列是table.so我需要从表中同一列的fromdate到todate的数据。
提前谢谢,帮帮我!。
Hi...
How to read table values using same column 2values in where clause,is it possible?
am reading data based on date value,but date is single column is table.so i need data from fromdate to todate within same column of table.
thanks in advance,help me!.
推荐答案
尝试:
Try:
SELECT * FROM myTable WHERE myDateColumn BETWEEN '2013-01-31' AND '2013-06-01'
我的文本框值,
"my textbox values,
string fromdate = txtfdt.Text;
string format = "dd-mm-yyyy";
DateTime fdt = Convert.ToDateTime(fromdate);
string todate = txttdt.Text;
string Format = "dd-mm-yyyy";
DateTime tdt = DateTime.Parse(todate);
这些值,如何转换为ms访问日期/时间格式。帮助我。
不要 - 作为参数化查询传递它们:
these values,how to convert into ms access date/time format.help me."
Don't - pass them through as a Parametrized query:
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (OdbcCommand com = new OdbcCommand("SELECT * FROM myTable WHERE myDateColumn BETWEEN @FD AND @TD", con))
{
com.Parameters.AddWithValue("@FD", fdt);
com.Parameters.AddWithValue("@TD", tdt);
using (OdbcDataReader reader = com.ExecuteReader())
{
while (reader.Read())
{
...
}
}
}
}
这篇关于如何使用where子句从数据库中读取多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文