|
Your core problem is that you're doing things badly. Don't store dates as strings, it limits what you can do with them, and causes these sort of problems. If you must write it that way for now ( even tho I hope you'd learn never to do it again ), you can write code that forces a format string, something like datetime.ToString("MM-DD-YYYY"), I believe.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hey Christian
lapdog is my colleague, he just stepped out...
its not that we need to store the dateTime as text, but rather that when we send it to a sqlStoredProcedure well do something like this..
cmd.commandtext = "sp_someStoredProcedure " + myDateTime.ToString();
is there a better way of sending sql this dateTime?
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
HarveySaayman wrote: is there a better way of sending sql this dateTime?
Very much so
cmd.CommandType = CommandType.StroredProcedure<br />
cmd.CommandText = "sp_someStoredprocedure";<br />
cmd.Parameters.Add(new SqlParameter("@myDate",SqlDbType.Date));<br />
cmd.Parameters["@myDate"].Value = myDateInstance;
(typed quickly, errors may be present, you should get the idea)
|
|
|
|
|
Hey J4amieC,
thanx alot, that seems to be working!
now id like to run a different scenario by you also about dates and times. in my communication application i get data from an external device, a fingerprint scanner to be exact. now it send me the dateTime in a string and there is nothing i can do about that.
so currently when i add it to the dataBase i do this...
<sqlcommand insertcommand="new" sqlcommand(="sp_InsertIntoAccessPunches" ,="" newsqlconn);<br="" mode="hold" />insertCommand.CommandType = CommandType.StoredProcedure;
insertCommand.Parameters.Add("@dateTime", SqlDbType.DateTime);
insertCommand.Parameters["@dateTime"].Value = DateTime.Parse(dateTime);
insertCommand.Parameters.AddWithValue("@empNo", empNo);
insertCommand.Parameters.AddWithValue("@TerminalID", terminalID);
cmd.ExecuteNonQuery();
what do you think?
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
|
I don't see any code that would make you feel that the data source should be edited ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
sorry i didnt get you?
A pencil icon appears in datagrid whenever we edit any of its column.This icon is not appearing after insertion of combobox or any other control.Hence a new row is not getting added to datagrid.I need to perform insertion of data in database using datagrid.
|
|
|
|
|
sarilee wrote: A pencil icon appears in datagrid whenever we edit any of its column.
This occurs in a gridview, if you happen to configure it to use such an icon. I didn't know a datagrid supported that behaviour at all.
sarilee wrote: I need to perform insertion of data in database using datagrid.
OK - then you need to render the controls that will contain the data and write database code to store it. Sounds like you're half way there.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
i got a solution of my problem.
Thanks
|
|
|
|
|
is it possible to implement item templates in datagrid in windows forms?
|
|
|
|
|
I don't believe so, the templates are borne of webforms using HTML to start with
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello everyone,
For example, my class Foo wraps an object of StreamWriter, I must make Foo implements IDisposable and in the Dispose method of class Foo, invoke Dispose method of the StreamWriter object instance to release resource properly?
using System.IO;
public class Foo : IDisposable
{
StreamWriter a;
public Foo()
{
}
public void Dispose
{
if (null != a)
{
a.Dispose();
}
}
}
thanks in advance,
George
|
|
|
|
|
George_George wrote: I must make Foo implements IDisposable and in the Dispose method of class Foo, invoke Dispose method of the StreamWriter object instance to release resource properly
Yes that's correct. But the pattern you used to implement IDisposable is not correct. You may check this[^] to get an idea for implementing the same.
If you are using StreamWriter instance only in a method, declare it inside the method and wrap it in a using block, hence you can avoid implementing IDisposable in class Foo .
|
|
|
|
|
Thanks N a v a n e e t h,
I have read through the article, looks great and answered most of my questions. One question which is not answered is what is the relationship between Finalize method and destructor?
Finalize will call destructor or vice versa? Or no relationship? GC will call Finalize, but I am not sure whether GC will call destructor as well?
regards,
George
|
|
|
|
|
George_George wrote: what is the relationship between Finalize method and destructor?
As far as the CLR is concerned, in C# something looks like a destructor is finalize method. System.Object has a Finalize() method, but C# won't allow you to override this. In C#, destructor is called as finalize method. To make it more clear look at the below class which uses a destructor and check the IL generated code
class Program
{
static void Main(string[] args)
{
}
~Program()
{
}
}
.class private auto ansi beforefieldinit Program
extends [mscorlib]System.Object
{
.method public hidebysig specialname rtspecialname instance void .ctor() cil managed
{
}
.method family hidebysig virtual instance void Finalize() cil managed
{
}
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
}
} In the IL code you can see the Finalize() method. So C# compiler converted destructor to this Finalize() method. This will be called by garbage collector.
Considering performance, implementing destructor is costly. GC will maintain a separate queue for items that need finalization. So you should implement the Dispose() pattern and clean all your resources. Also call GC.SuppressFinalize() from dispose which will suppress the finalization.
Hope things are clear now
|
|
|
|
|
Thanks N a v a n e e t h,
1.
Which tool are you using to check IL code?
2.
N a v a n e e t h wrote: GC will maintain a separate queue for items that need finalization. So you should implement the Dispose() pattern and clean all your resources. Also call GC.SuppressFinalize() from dispose which will suppress the finalization.
I do not understand why using Dispose is faster than using GC Finalize? GC may have some smarter ways to treat all the to be finalized resources altogether?
regards,
George
|
|
|
|
|
George_George wrote: Which tool are you using to check IL code?
I use reflector[^]. It's a great tool
George_George wrote: GC may have some smarter ways to treat all the to be finalized resources altogether?
Yes, GC is smart. But you can't predict when GC will collect the resources. So implementing your own disposal methods, you are ensuring that all the unmanaged resources are deallocated once you finish with particular object. You won't be waiting for GC to clear that. Also classes that have finalize method, GC need two cycles to reclaim the memory fully. So it's an overhead.
|
|
|
|
|
Thanks N a v a n e e t h,
I watched it is not a Microsoft tool. So, Microsoft does not provide a similar tool?
regards,
George
|
|
|
|
|
Nope . But it is written by a Microsoft employee. It's must tool for every .NET programmers toolbox.
PS : I like the way you ask questions. It's clear and up to the point. Keep it up.
|
|
|
|
|
Thanks for your help, N a v a n e e t h!
I am previously a C++/Java developer, and I am new to C#. Happy to learn from you, especially for what are not given by MSDN.
regards,
George
|
|
|
|
|
|
Thanks gareth111,
I have read through the article, looks great and answered most of my questions. One question which is not answered is what is the relationship between Finalize method and destructor?
Finalize will call destructor or vice versa? Or no relationship? GC will call Finalize, but I am not sure whether GC will call destructor as well?
regards,
George
|
|
|
|
|
Hi guys.
I want to play video files (*.mpeg, *.avi, ...) in my application with C# and DirectX . but I do not know how I do it?
Can you help me ? thanks.
www.mds-soft.persianblog.ir
|
|
|
|
|
You use the windows media player control, or managed direct show ( which is in the platform SDK nowadays ) to play video files. A cursory search of the web would give you tons of samples
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
ok, thanks.
Only God
|
|
|
|