|
That can't be done. The struct is DateTime not Date. You can either ignore the time part altogether (be careful in any DateTime comparisons - Use the Date property of the DateTime to retrieve the DateTime with the default time e.g. DateTime.Now.Date ) or create your own class/struct to just hold the date and create implicit/explicit operator overloads to/from DateTime .
[Edit} A little code to help you get started and to show how easy it is to create a wrapper to DateTime [/Edit]
public struct Date
{
public static readonly Date MaxValue = new Date(DateTime.MaxValue);
public static readonly Date MinValue = new Date(DateTime.MinValue);
private DateTime _DateTime;
public Date(DateTime dateTime)
{
_DateTime = dateTime.Date;
}
public static implicit operator DateTime(Date date)
{
return date._DateTime;
}
public static explicit operator Date(DateTime dateTime)
{
return new Date(dateTime);
}
public static Date Now
{
get { return new Date(DateTime.Now); }
}
public override string ToString()
{
return _DateTime.ToString("d");
}
public string ToString(IFormatProvider provider)
{
return _DateTime.ToString(provider);
}
public string ToString(string format)
{
return _DateTime.ToString(format);
}
public string ToString(string format, IFormatProvider provider)
{
return _DateTime.ToString(format, provider);
}
}
modified on Monday, September 7, 2009 9:29 AM
|
|
|
|
|
Thank you. This seems to shade some light. May The World End Soon and report functions be developed in .NET . Today is Monday.. I have a little Headache
|
|
|
|
|
You are completely clueless.
Once you have a datetime object, it is up to YOU to write code to format it to display the way you want.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
You can always use the following
DateTime dt = DateTime.ParseExact(string, "MM/dd/yyyy", null);
string output = dt.ToShortDate();
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
use DateTime.Parse
|
|
|
|
|
Just for example :
string dateStr = "20.01.1980 13:59:59";
DateTime dateTime = DateTime.ParseExact(dateStr, "dd.MM.yyyy HH:mm:ss", new CultureInfo("de-DE"));
Console.WriteLine(dateTime);
|
|
|
|
|
.Net has datetime combined type
SQL Server 2008 has date and time types seperately....
figure out how to use SQL 'Date' type in .net or else write you own class. all the best
Ravie Busie
Coding is my birth-right and bugs are part of feature my code has!
|
|
|
|
|
Hi everyone
First I'm trying to return multiple rows from a table via XML:
string strSQLCommand = "SELECT * FROM Magazalar WHERE Sehir = '" + a + "'";
SqlCommand command = new SqlCommand(strSQLCommand, conn);
TableRowCollection returnvalue = (TableRowCollection)command.ExecuteScalar();
a is cannot be null and the query may return a single row or multiple rows.
then, I want to show this returned row collection in a table:
MagazaShowTable.Rows = returnvalue;
The compiler says that Table.Rows is a Read-Only, and sth cannot be assigned to it, and I couldn't find any suitable option rather than .Rows ...
Can anybody help?
|
|
|
|
|
Hi,
first of all be aware that command.ExecuteScalar() returns the first column from the first row, not multiple rows.
Then as the compiler already says, Rows is a ReadOnly-Property. You could add the rows by using MagazaShowTable.Rows.Add
|
|
|
|
|
Thanks for answering...
So what is the suitable function for calling multiple rows? command.ExecuteReader() ?
I'm converting the returned value to TableRowCollection, is it right?
and how I can I show this row collection in my table?
|
|
|
|
|
ExecuteReader is what you need. The returned value is a SqlDataReader. With this you can iterate through the rows. Simpler approach is to use a dataset with a dataadapter. This will read the rows within a table anyway.
But first you can use ExecuteReader, iterate through the rows and add the rows with values to your datatable.
|
|
|
|
|
I'll give it a try
thank you!
|
|
|
|
|
|
|
|
|
Hey... don't repost your question. You've got the answer. It's an attribute.
To know, what is an attribute, go to GOOGLE or MSDN. Learn first.
|
|
|
|
|
i m getting google results for attribute to a method.
i want to know what exactly is attribute when passed to method parameter.
Sorry for reposting, but plz explain.
Ravie Busie
Coding is my birth-right and bugs are part of feature my code has!
|
|
|
|
|
Its an attribute on the parameter, nothing is getting passed other than the parameter itself.
you can, by reflection find the parameter on the attribute to inspect its value.
The code you have is ,erm, unusual to say the least so I doubt you'll get much help over that you have already. I've been using c# since 2001 and haven't seen parameter attributes except in your post.
I *suspect* that there is a massive and dirty hack in the source code you have. Check the attribute and see if any the attribute code does anything, if so, the orignal programmer pobably intended for the code to be called each time the method is called. That would be appalling however.
|
|
|
|
|
Is your question not answered? What do you want to know exactly?
|
|
|
|
|
Don't repost your questions. It's very rude and drowns out the interesting ones.
|
|
|
|
|
Hi, guys,
How could I make it possible to drag down and select even those parts which are invisible when drag event starts? Similar to Notepad or MS Word tools. Any suggestions would be appreciated!!
Best Regards!
I don't wonder what, but wonder why...
|
|
|
|
|
Leapsword wrote: How could I make it possible to drag down and select even those parts which are invisible when drag event starts?
Drag on what?
What sort of application is it? Windows Forms, ASP.Net, Web; what?
What Controls are you using, what are you dragging on/over?
To get an answer to your problem, you have to describe it fully.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi, Henry,
Sorry for my careless mistake. I am still working on Windows Forms Application, and the control I am using now is a TableLayoutPanel, I want to drag over this control, but since there will be also a scrollbar next to this Panel, and this Panel is not showing totally the whole, I am expecting a kind of event which can handle this and if user didn't release the mouse, the Panel can move down as well as the scrollbar scrolls. Is this clear enough now? Your kind help is so much appreciated!
Sincerely
Liang
|
|
|
|
|
Hello everyone
I need to save the word file as PDF.
I am using Microsoft.Office.Interop for that
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
But after it gets saved to the destination folder, pdf doesn't get open,
as the pdf file gets corrupted.
Please help me to do this job done.
Thanks & Regards
Sheetal Rawat
|
|
|
|