Try this out:
just modify your while loop and use this code.
var Date = Convert.ToDateTime(dr["Date_Time"]);
Date = Date.AddMinutes(15);
MessageBox.Show(Date.ToString());
Hope this helps!
Question
Hi I am developing an application to retrieve data from one database server to another in C# Visual Studio 2010.
There is a requirement that data should be retrieve from the database by software installation date means a specific date to now means current time.
There is also one more condition that when we get the oldest record like 2010-03-05 16:30:23
, the next record and the first record difference should be 15 minutes like next record should be 2010-03-05 16:45:23
. Database having records per minute.
I have been tried the below but it's not fulfilling the requirement.
try
{
var con = new SqlConnection(Properties.Settings.Default.sConstr);
var cmd = new SqlCommand("SELECT * from RAW_S001T01 where Date_Time >='" + time + "'", con);
con.Open();
var dr = cmd.ExecuteReader();
var count = 0;
while (dr.Read())
{
var Date = (dr["Date_Time"].ToString());
var temp = Date.ToString(CultureInfo.InvariantCulture);
var UTime=time.Split(':');
string tempa = UTime[1].Substring(0, 2);
time = temp +int.Parse("15");
MessageBox.Show(time);
}
}
catch (Exception ex)
{
MessageBox.Show(@"Error.",ex.ToString());
}
How can we resolve this?
La solution
Try this out:
just modify your while loop and use this code.
var Date = Convert.ToDateTime(dr["Date_Time"]);
Date = Date.AddMinutes(15);
MessageBox.Show(Date.ToString());
Hope this helps!
Autres conseils
Just set the 15 minutes later time in a variable (as per Abhishek's answer).
Then process all items less than that time. When you find an item with a time greater than that time, update that time (add another 15 minutes) and redirect the output to the next section of your data structure. Keep looping until you finish.