I have a problem with converting datetime, I do not see where I make a mistake. I think it should be somewhere to date a date for the same sql query to recognize This is the result I get when I set up a break point This is the result at the base
This is my code with which I send the data
var arravialDates = dataAccess.get_dates(userID, date, DateTime.DaysInMonth(date.Year, date.Month)); //get dates for user
//working hours
DateTime dateH = new DateTime(2099, 12, 12, 0, 0, 0);
bool hasDate = false;
for (int i = 0; i < arravialDates.Count; i++)
{
var arravial = dataAccess.getPraesenzzeit(arravialDates[i], userID);
int index = 0;
}
Your screenshot shows a .Query<>
method. SqlConnection
has no Query
method.
Dapper does, a microORM used to make writing parameterized queries easier. You don't need string interpolation or concatenation when using Dapper or any other ORM. Just write :
var output=connection.Query<PRAESENZZEIT>(
"select * from Z_PRAESENZZEIT " +
"where ZPZ_Datum = @date and ZPZ_LPE_ID= @id "
"order by ZPZ_ID_ASC",
new {date=DatTime.Today,id=1});
Better yet :
var query = "select * from Z_PRAESENZZEIT " +
"where ZPZ_Datum = @date and ZPZ_LPE_ID= @id "
"order by ZPZ_ID_ASC",
var output=connection.Query<PRAESENZZEIT>(query,new {date=date,id=userid});
You are wrong in your approach. You should never create a SQL statement through string concatenation. You are prone to SQL injection, you will experience formatting problems on different systems, and you will have a high impact on the performance of the query parser.
The solution is to use parameterized queries: you add a placeholder for a parameter and add the value through the command parameters.
Your SQL should look like where ZPZ_Datum = @zpzdate
, then you add a parameter with the name zpzdate
: command.Parameters.Add("@zpzdate", arravial);
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With