开发者

Fetching the data from database for specific time

开发者 https://www.devze.com 2023-03-14 14:44 出处:网络
Hello here i want fetch the data from databaseinto datagridview for timer interval BETWEEN 1900-01-01 23:00:00.000 AND 1900-01-01 06:59:59.999 but here i am unable to do that can anyone help me......

Hello here i want fetch the data from database into datagridview for timer interval BETWEEN 1900-01-01 23:00:00.000 AND 1900-01-01 06:59:59.999 but here i am unable to do that can anyone help me .......

temprature Time                         date
27         1900-01-01 00:46:09.000  2011-06-16 00:00:00
27.3       1900-01-01 00:48:09.000  2011-06-16 00:00:00
27.6       1900-01-01 00:50:09.000  2011-06-16 开发者_开发百科00:00:00
27.9       1900-01-01 00:52:09.000  2011-06-16 00:00:00
28.2       1900-01-01 00:54:09.000  2011-06-16 00:00:00
28.5       1900-01-01 00:56:09.000  2011-06-16 00:00:00
28.8       1900-01-01 00:58:09.000  2011-06-16 00:00:00
29.1       1900-01-01 01:00:09.000  2011-06-16 00:00:00
29.4       1900-01-01 01:02:09.000  2011-06-16 00:00:00
29.7       1900-01-01 01:04:09.000  2011-06-16 00:00:00


This question is heavily dependent on which database you have, but I'll take a wild shoot over here, I'm assuming that you're using Ado.Net and have a SQL Express database, to get those rows, you should do something like this:

// your connection string should be like
// Data Source=localhost\SQLEXPRESS;Initial Catalog=YourDbName;Integrated Security=True
var connectionString = "A connection string";

var connection = new SqlConnection(connectionString);
var query = new SqlCommand("SELECT temperature, startDate, endDate FROM yourTable", connection);

connection.Open();
var dbReader = query.ExecuteReader(CommandBehavior.Default);

Console.WriteLine("Temperature\tTime\tDate");

while (dbReader.Read())
{
    var row = new object[dbReader.FieldCount];
    dbReader.GetValues(row);

    var temperature= row[0].ToString();
    var startDate = DateTime.Parse(row[1]);
    var endDate = DateTime.Parse(row[2]);

    Console.WriteLine("{0}\t{1}\t{2}", temperature, startDate, endDate);
}

Again, this answer is assuming a lot of things about your question, because you should have specified your database type, the columns of your table and how you're accesing the database, but with any luck, this code may be a starting point for you.

Hope it helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号