I am trying to read "DateComposed" and "timeComposed" values of Notes Discussion Database using Domino.dll. While reading I am getting "" for both of them.
Sample code:
DateTime DiaryDate = (DateTime)((object[])docJournal.GetItemValue("DateComposed"))[0];
DateTime dtTimeCreated = (DateTime)((object[])docJournal.GetItemValue("timeComposed"))[0];
Is there another way to read them?
Try the document "GetItemValueDateTimeArray" method instead of "GetItemValue"
Actually, the DateComposed and TimeComposed fields are "Computed for Display" fields, meaning these are not actual fields stored on the document, but are computed on the fly when a document is rendered through a form. In looking at the form design of the out-of-the-box Notes Discussion template, I see those two fields are computed based on the document's internal created date. So, take a look at the getCreated method, which returns a DateTime. You can then parse out the date and time values.
Try something like this:
...
Document docJournal = ...
DateTime DiaryDate = docJournal.getCreated().getLocalTime();
...
Related
I tried to use
sqlDr.GetValue(a).ToString()
to display a DATE column from my database which looks like this..(the Date Submitted column)
But the problem is , when i display it using getValue(8).toString(), something like this is displayed..
Thanks for taking your time to read my post , any reply is much appreciated!
The problem is .Net does not have a Date-only primitive type. Therefore the Sql Server Date column type maps to a full DateTime value in .Net, which always includes a time component. If you don't provide a time component, the DateTime struct will have a 0-value time component, which maps to 12:00:00.000 AM.
To get around this, you need to specify the output format for your column, so that it explicitly does not include a time value. You want something like this:
((DateTime)getValue(8)).ToString("d")
However, the exact code you need will vary wildly depending on how your result table is created. If necessary, check the SqlDataReader.GetDataTypeName() function to know what type you're dealing with.
Try using the DateTime.ToShortTimeString Method ():
Console.WriteLine("Short date string: \"{0}\"\n", myDateTime.ToShortDateString());
Output: Short date string: "5/16/2001"
I have a string that is written out like an XML file. An example would look like this:
string = <Employees><EmployeeId>1</EmployeeId>< ... ></Employees>
I am saving this in a table because I wanted to audit changes, but I didn't want to have multiple tables for different audits. This is because it would record changes to things other than employees. So using an XML style string in the database seemed like a good suggestion.
Now to the real business. I want to check to make sure that there were actually changes to the employee because one could go into the edit page, change nothing, and click save. As of right now, the data would write to the DB and just clutter it up with non-changed data.
I'd like to be able to check if the XML styled string that is going to be saved is on the database, so if <employees><employeeid>###</employeeid> == "changes" and then see if the whole string equals the other. Basically, check the employeeId first because that won't change, and then check the string as a whole to see if there is any difference. I would have just checked the first n numbers, but the id number could have a length of 1 to 3.
Also, because it is styled as XML, is there an easy way to convert it to read it like an XML file and check that way?
Storing arbitrary data in a column is a form of denormalization. You can't really do much with it at a database level. However, SQL Server does have an XML column type. Entity Framework doesn't support mapping to/from an XML column, so it will simply treat your XML as a standard string. With this column type, though, you can write actual SQL queries against your XML using XPath expressions.
Your best bet, then, is to type your column as XML, and then write a stored procedure that performs the query you need. You can then utilize this stored procedure with Entity Framework.
For more information on the XML column type see: https://msdn.microsoft.com/en-us/library/ms190798(SQL.90).aspx
I retrieve value from database like this 173557.0000. I want to display like 1,73,557.00.
This is my code what tried
Table1001Hour.Rows[i].Cells[0].Text = rd["hour"].ToString();
Table1001Hour.Rows[i].Cells[1].Text = string.Format("{0:C}", Convert.ToInt32(rd["salesCost"].ToString()));
But it throws an error message.
Input string was not in a correct format.
If I don't convert to string it shows like same as it is 173557.0000
Thanks
It looks like the problem is here:
Convert.ToInt32(rd["salesCost"].ToString())
So... don't do that? The data coming back from the database is probably just an int, so: (int)rd["salesCost"] (or, if you're unsure of the specific type, Convert.ToInt32(rd["salesCost"])) should be fine. You could also then use the overload ToString; giving you:
Table1001Hour.Rows[i].Cells[1].Text = ((int)rd["salesCost"]).ToString("C");
(although based on the .0000, it could be decimal or double - the latter of which would be a very bad choice for financial data)
To be honest, I think it is a mistake to have UI code and DB code touching each-other directly, but that might just be me. If it were me, I'd be populating an object model from the database, and separately writing the object model to the UI.
I have this 21/10/1999 value manually inserted into the SQL database and when I retrieve it like this:
txtDOB.Text = readPatient["pDOB"].ToString();
It displays everything along with the time 12:00:00 AM. My data type for my date column is date, not datetime. So why is it displays the time as well?
((DateTime)readPatient["pDOB"]).ToString("d");
For a list of supported formats see: http://msdn.microsoft.com/es-es/library/zdtaw1bw(v=vs.110).aspx
You may try
txtDOB.Text = Convert.ToDateTime(readPatient["pDOB"]).ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
Edit: Thanks to comments saw that forgot to cast to datetime
It looks like you got your answer on how to properly format the value to a string without the time portion. But, no one has answered your other question:
So why is it displays the time as well?
This is because of mappings between SQL and .NET. In .NET a SQL "date" is stored in a DateTime object which does have time as well. To see all mappings between SQL and .NET see this: SQL Server Data Type Mappings
you can try this
txtDOB.Text=Convert.toDateTime(readPatient["pDOB"]).ToString("d/MM/yyyy");
You can use the string format parameter of the ToString to achieve any format you like,
like this:
TextBox1.Text =Convert.toDateTime(readPatient["pDOB"]).ToString("d/MM/yyyy");
Click on the datetimepicker then go to properties. There you can format your datetimepicker. Change format to custom (there few selection there) then set custom (provided in the properties menu) table with yy-MM-dd,an
DateTime dt = Convert.ToDateTime(sqdr["invdate"].ToString());
dt.Date; //To get the date only
Hi all i will read the required Content from an Excel sheet so that i will get the required data and i am saving that to List<String> as follows
Now i would like to have my dataset in such a way that i would like to format in this way
Is it possible to do as per my requirement if so can any one help me..
There is nothing natively that can do this for you in the .NET framework; I'm not sure if anything exists in open source/third-party. It wouldn't be extremely difficult to build a routine to convert the data in the format you like.
Well, I am not coding it for you, but it is easy, if I understood your question well. Iterate the list while DateTime.TryParse returns true, so you get all column names (year, months). Then you have to do something custom for the description columns. For showing the float data do the same, iterate while Float.TryParse returns true...