2
Answers

time difference

string timespent1 = "SELECT DATEDIFF(minute ,departureTime,entryTime) AS timespent FROM mambo where plateno = '" + TextBox1.Text + "'";
SqlCommand comman = new SqlCommand(timespent1,conn);
comman.Parameters.AddWithValue("@timespent",ToString());
SqlDataReader reader=comman.ExecuteReader();
while(reader.Read())
{
Console.WriteLine(reader[0]);
}
i have been trying to use the above code to calculate time difference and store the result in DB column timespent but not working. what could be the problem and the solution to it. 
Answers (2)
0
Nitin Sontakke

Nitin Sontakke

NA 11.7k 2.2k 8y

Just mentioning "but notworking" unfortunatelydoesn't explain much about what is happening.

Please give more info, what you are getting, if you are getting error, please give details.

Anythingthat would help us help you better.
0
Joginder Banger

Joginder Banger

NA 10k 490.7k 8y
Hi Simon,
if you want get time difference only that why pass parameters. You can easily with like.
string timespent1 = "SELECT DATEDIFF(minute ,departureTime,entryTime) AS timespent FROM mambo where plateno = '" + TextBox1.Text + "'";
SqlCommand comman = new SqlCommand(timespent1, conn);
conn.open();
string ReturnValue = comman.ExecuteScalar();
check your data in ReturnValue.