Manually Binding A RadGrid with non-standard date format? - asp.net

I attempting to manually bind a radgrid to a view. The issue is I need to query by dates and sort by dates, however the original developer stores the dates as strings in the DB and with a non-standard format of "yyyyMMdd"
Is there a way to automatically bind it, or do i have to do a manual bind? If i have to do it manually what is the best way to do this? Read the view into a datatable? Re-Cast all of the dates, and then bind the datatable to the grid?

In the NeedDataSource event use a LINQ selector to get the values and convert the date stored in the database to a TimeStamp.
Alternatively you can modify the given column to have a TimeStamp value in the database (make sure you are using a transaction, not allow writes to that table and save all the values temporarily somewhere so you can load them back, maybe into a temporary table having the id and the date).

Related

D365 FO - Passing date range in query [duplicate]

I need to create simple query which will show all contracts which will expire in next 3 months. I know how to do that with SQL, but how to do that in Visual Studio when I create query. I added data source Contract table. Added range. Column where is date about expiring is VALIDTO.
So, something to write up in value, or how to do that ?
Solved with two ranges on VALIDTO column. Used (MonthRange(0,3)) with (Day(0)) formulas.

Format date from lookup table

My report has a data lookup table with dates in dd/mm/yyyy formart. When I bring it into Crystal it changes the data type to date-time instead of just date.
I tried converting to just a date within Crystal, but when I run a lookup based on parameters (10-1-2016 - 10-31-2016) I get a running cycle of dates. As soon as it hits 10-31-2016 it starts over from 10-1-2016.
I tried setting it to not provider duplicate values to no avail. How I could be doing this better?
If you just need to display the date without the time value, you can format the field when it displays in your report as "System Default Short Format" in the Format Editor. (Date and Time tab)
Otherwise leave the date as-is and create a seperate Formula Date({table.Field}) to use as "just the date". This way you keep the original datetime value as-is, but can use your new Formula when the time value needs to be removed.

How to add Timestamp value in SQL Server 2005 by using LINQ

My database table have a Timestamp column named as inTime and i am using LINQ for insert, update data in SQL server. Now i want to add the timestamp value in my database but i don't know how to insert?
spaBL.attendance obj = new spaBL.attendance();
obj.FK_employeeId = 1;
obj.inTime =[what to write here??]
inTime is of timestamp type.
Timestamp as in SQL Server Timestamp data type?
;) If I got a cent every time someone did not read the documentation and thought that is a TIME STAMP I would be more rich than bill gates.
Timestamp data time has NO TIME INFORMATION IN IT. It is a running version number, legacy to Sybase SQL Server where SQL Server from Microsoft originated and a totally borked design.
So, no, you CAN NOT SET THAT FIELD, sorry, and it has no usable value except to see whether it changed (then the row was updated).
The documentation is explicitly clear on that, even if some people think reading is maybe a lost art:
http://msdn.microsoft.com/en-us/library/ms182776(v=sql.90).aspx
Is a data type that exposes automatically generated, unique binary
numbers within a database. timestamp is generally used as a mechanism
for version-stamping table rows.
There is no way for you to set it. CHange your LINQ setup to not update this column.
Timestamp values are auto generated by the server on inserts. You should insert rows to the table without supplying a value for the timestamp column. Sql server will then generate the value for the column.
Note the columns of type timestamp does NOT contain values that can be parsed as a DateTime. The idea behind timestamp columns is that they can be used to check if a row has been updated between fetching the row and trying to update the row with new values.
You do not provide values for columns with a Timestamp (Rowversion) data type. SQL Server will provide a value for you automatically (and it won't be a datetime value). Therefore you do not need to be concerned with having Linq To SQL insert a Timestamp value for you. In fact, you cannot do it. SQL Server will do it for you. You can however, retrieve the value of a Timestamp column. I believe the corresponding C# type will be System.Data.Linq.Binary.
How to add Timestamp value in SQL database by using LINQ
hope it helps
You cannot update a timestamp. See here. And indeed, as TomTom indicated, it doesn't contain actual time information.

How to update DATETIME field with existing data from same table

I have an sqlite database which currently holds an integer field called Year which currently only stores the year. In future versions I want to store a full date and time.
I updated my table to include a FullDate field using alter table.
> ALTER TABLE Files ADD COLUMN UploadDate DATETIME DEFAULT 0;
Next, I want to migrate all the existing year fields to the new field. So I'm looking for something like:
> UPDATE Files SET UploadDate = (DATETIME('%Y-%m-%d', Year, 1, 1));
Unfortunately this doesn't seem to work as the result is empty. I also tried the date and strftime functions but they either result in incorrect data or empty data.
What's the proper way to update a DATETIME field with existing data in the same table?
The DATE and DATETIME functions don't have a format parameter.
For more: http://sqlite.org/lang_datefunc.html
The main catch is that SQLite does not have any date or time types, so that you might as well populate your field with:
UPDATE Files SET UploadDate = Year || '-01-01';
And that will do the exact same thing. Dates are not stored as typed, but can be evaluated as such against the date and time functions.

Converting DateTime data to String in dataset

I have a dataset which stores dates in a DataColumn (datatype of this column is DateTime). I need to change the format from DateTime to string that will give me the date as per my current culture.
In case of a single DateTime variable, I can use the overloaded ToString() to achieve this in the following manner:
DateTime.Now.ToString(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)
But I need to convert data for all the rows in my DataSet to string. Does anyone have an idea on how I can achieve this?
Thanks.
When you get the DataSet:
locate apropriate DataTable
add new DataColumn
in one loop you populate new Column with (your DateTime).ToString()
Get the Dataset.
for each row convert to string and
put it in new dataset (along with
rest of data).
I don't think it's possible to change a column type after the table been filled. I think you should create a second table on your dataset and copy the information you need transforming the date in the process.
New answer :)
I have been googling an came up with this site: Linq to Dataset
That example shows how you can use linq on a dataset, I am guessing that you could use a query to perform the data transformation and place it on the new datatable. Not sure if it will perform better then the loop
If I were you, I would keep the data in the DataTable as it is. It is after all, meaningful data that would lose its meaning upon conversion. I would make any desired modifications only when displaying/rendering the data because that implicitly requires a conversion of the data into strings (with optional formatting).
Any DateTime variable can be rendered as a string (with culture-sensitive formatting) using the simple code:
DateTime.Now.ToShortDateString();
// Or
DateTime.Now.ToString("d");
This function already uses formatting information derived from the current culture.
I really would suggest that you take another look at your scenario to evaluate if you really need to change the datatype of data in the dataset itself. (or provide us with more information)

Resources