sql statement

  • Thread starter Thread starter jed
  • Start date Start date
J

jed

string selectstr = "SELECT SUM(hrs) AS total_hours,SUM(mins)AS
total_mins FROM Timerecords WHERE (workdate >='" +
Convert.ToDateTime(dateTimePickerfirst.Text) + "')AND (workdate<='" +
Convert.ToDateTime (dateTimePickersecond.Text) + "')";

I have two datepickerboxs that i want to select dates in.I want the
selectstr string to recieve the values of the the calculated hours and
the calculated minutes but it must only sum up the values between the
two dates that i select in the datepickerboxs.
 
string selectstr = "SELECT SUM(hrs) AS total_hours,SUM(mins)AS
total_mins FROM Timerecords WHERE (workdate >='" +
Convert.ToDateTime(dateTimePickerfirst.Text) + "')AND (workdate<='" +
Convert.ToDateTime (dateTimePickersecond.Text) + "')";

I have two datepickerboxs that i want to select dates in.I want the
selectstr string to recieve the values of the the calculated hours and
the calculated minutes but it must only sum up the values between the
two dates that i select in the datepickerboxs.

Well, you haven't actually asked a question here, but one thing I
would *strongly* recommend is using a parameterised query instead of
embedding the date/time values directly in the SQL.

Jon
 
Hi,

string selectstr = "SELECT SUM(hrs) AS total_hours,SUM(mins)AS
total_mins FROM Timerecords WHERE (workdate >='" +
Convert.ToDateTime(dateTimePickerfirst.Text) + "')AND (workdate<='" +
Convert.ToDateTime (dateTimePickersecond.Text) + "')";

I have two datepickerboxs that i want to select dates in.I want the
selectstr string to recieve the values of the the calculated hours and
the calculated minutes but it must only sum up the values between the
two dates that i select in the datepickerboxs.

I dont see a question in the above post.
If you want to know how to get those two values back there are several ways,
you can use ExecuteReader() and get the first value of the returned dataset,
or you could use output parameters.

Be more especific and you may get a better answer.
 
In addition to the other comments about using a parameterized query, you are
converting text values to DateTime objects in your SQL string concatenation.
If you are going to concatenate objects into a string, they have to be
strings, not DateTime objects.

No - if there are any non-string types in the statement,
string.Concat(object[]) is used. For instance:

using System;

class Test
{
static void Main()
{
string x = "The date and time is: "+DateTime.Now+".";
Console.WriteLine(x);
}
}

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top