|
Hello
I am working on a system for C #. NET
Problem
The date in the screen 12/01/2010
But when I store the date in the database sqlServer storage is as follows
22.06.1905
What is the problem
How can I solve this problem
thanks
Thaer
|
|
|
|
|
Without seeing your code, it is difficult to tell.
Best guess is that you are storing the date as a string, the format of which is local to your region and / or culture. SQL databases use an internal format of "YYYY-MM-DD" and are culture invariant.
Do not keep your date as a string - store it in a DateTime and pass that to the SQL directly. Convert it to a display string as late as possible, and convert from a string as soon as possible. Not only is it more efficient in terms of space, but you can easitly perform operations such as comparisons, additions, etc. which you cannot with a string.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Hi,
your question isn't particularly clear, however this[^] might be useful.
|
|
|
|
|
I'm not exactly sure what you mean. Do you want to store the Date in a specific manner? If that's the case then check if SQL supports your date format. If not make a function that creates the date in the specified format.
Or you could create a DateToString() method or the other way around.
Any way you could use: dt = DateTime.Parse() and then
check the month,year and day.
Again I'm not sure what you want.
|
|
|
|
|
Hi fellow developers.
I come with 2 questions today around the area of serialization. I would normally try these things out myself, but I am away from my development machine today and I was wondering you if you could provide some assistance.
If you added a new property to an existing class that your web service serializes and returns to clients, would it break for existing clients?
If you changed the data type of an existing property of an existing class that your web service serialises and sends to clients, would it break for existing clients?
Many thanks,
TF
|
|
|
|
|
Hi,
Adding a new property would normally not break existing clients. Since this is a web service and the client might consume the soap-formatted XML responses in any way there is no guarantee. For example, a client *could* have been implemented in such a way that it assumes the fifth childnode of some element to be "dateOfBirth" and parse it's text as a date, and this would obviously fail if the message format changed so that dob no longer was the fifth childnode. However, part of the point of using XML is of course to enable to use the node names instead, so picking nodes by index is bad practice.
Changing the type of an existing property is much more likely to break existing clients, though it need not always happen. Again things are fuzzy since a client could be implemented in any of a number of technologies, and with any number of tools. Changing from "int" to "byte" might be safe, but might not. I don't know the type definitions in W3C's standards, but generally the only safe changes you can make (that cannot break properly implemented clients) would be thos that result in the property still mapping to the same type in the SOAP message.
You might be thinking of only a subset of the possible clients though, such as .NET clients generated with Visual Studio. Even then there are a few varieties; at least two: WCF clients configured to connect to a web service endpoint, and "pure" web service clients. Adding a property to a class won't affect such clients. Changing the type will also be fine as long as the values actually returned from the service are valid for the old type. Changing from Int32 to byte for example breaks nothing (but also doesn't achieve much), while changing from int to double works (but is pointless) only so long as the values returned fit in an int.
|
|
|
|
|
I am working with a DataGridView and I am subscribing to DataGridView.Scroll events. As soon as I get a scroll-event, I query the new cell display area:
private void dataGridView1_Scroll(Object sender, ScrollEventArgs e)
{
Rectangle r1 = dataGridView1.GetCellDisplayRectangle(0, -1, true);
Console.WriteLine("New cell position after scrolling: " + r1.X + ", " + r1.Y);
}
However, it seems the CellDisplayRectangle isn't updated by the time I get the scroll-event. What event should I subscribe to instead to get the correct CellDisplayRectangle after the DataGridView was scrolled?
|
|
|
|
|
I would put a boolean value to true, and handle event: RowPostPaint. This event occours after DataGridViewRow finish painting. And there it would check for that boolean property and execute.
private void dataGridView1_Scroll(Object sender, ScrollEventArgs e)
{
scrolled = true
}
private voud dataGridView1_RowPostPaint(Object sender, DataGridViewRowPostPaintEventArgs e)
{
if (scrolled)
{
Rectangle r1 = dataGridView1.GetCellDisplayRectangle(0, -1, true);
Console.WriteLine("New cell position after scrolling: " + r1.X + ", " + r1.Y);
scrolled = false:
}
}
|
|
|
|
|
Seems to work fine, thanks for your help!
|
|
|
|
|
Hi all,
I want to resize my string, getting rid of the last 5 chars.
for example:
after I do this:
string a= "example string 4444";
SomeMethod(a);
I want 'a' to become "example string" and " 4444" chars will be lost.
Is there a built-in function for such thing or should I create a simple algorithm?
Thanks...
|
|
|
|
|
Something like SubString?
|
|
|
|
|
I knew there was sth like this, I remember it from C times.
All I've got to do is to assign the "string size - 5" for starting pos.
thanks for reminding
|
|
|
|
|
Emmet_Brown wrote: assign the "string size - 5" for starting pos length
FTFY
|
|
|
|
|
string a= "example string 4444";
int numToRemove = 5;
a = a.Remove(a.Length - numToRemove - 1, numToRemove);
|
|
|
|
|
Hi,
use the substring function.
eg. a.SubString(0,14);
modified 27-May-14 4:57am.
|
|
|
|
|
Hi,
I am creating a deployment project. Everything works well except the uninstall of the previous version. if I look in the Programs and Features window in Windows 7 the new version is updated in the version column, but the application still picks up the old version. When I run the msi again it asks for repair or uninstall. I uninstall, run it again, install and then it works.
Can anyone maybe help.
Thank you
|
|
|
|
|
my app. send SMS in bulk
wat i want is to display the progress of SMS send.
Thread.delay (1000); is working but im not able to display that progress in lable.
why and wats the remedy???
|
|
|
|
|
if your app is a WinForms app and all of your code is running on the main thread, then Thread.Sleep(1000) will stall the GUI, which is not really acceptable; you should either use a timer to create a period of inactivity (a Windows.Forms.Timer keeps you on that main thread); or better yet, delegate the slow operations to another thread, have a look at BackgroundWorker.
Warning: you may want to read this[^].
|
|
|
|
|
Dear friends,
Small clarification.
Can some one tell me which one will be faster?
int a =100000;
string b = a.tostring();
string c = convert.tostring(a);
string d =""+a;
By
Joe.I
|
|
|
|
|
I think in release mode B and C have the same result. But for the purpose a.ToString() is the best one.
The D case is a coding horror for me.
|
|
|
|
|
Short answer: test it
I took a little look with the Reflector and I'm willing to hazard a guess: the first one. Because: the first one just calls Number.Format(something) which is an extern function, the second one calls int.ToString(some stuff) so basically it just adds a method call (which could be inlined by the JIT engine) and the last one also does some string appending, to which JIT magic may also happen, it might have an "if (first.Length == 0) return Second" and then the optimizer in the JIT compiler might decide that since the string is a constant, its Length is also constant, and then it might optimize that test away and skip the string appending completely.
That is very optimistic.
So, still test it..
Who knows, maybe it's even possible to write a faster IntToString method? I would look into it. Especially if a lot is known about the input (probability distribution etc). I wouldn't count on it, but you don't know until you try..
|
|
|
|
|
I don't know exactly. Test it!
However if you use a lot of int to string and then something like "string total = a+b+c+.... "
where a,b,c are strings obtained from ints than StringBuilder is the fastest and less
memory hungry.
|
|
|
|
|
I want to know how can I place a button or clickable label on the windows task bar so when clicking it will show a window just like Microsoft Windows Search?
|
|
|
|
|
jrahma wrote: I want to know how can I place a button or clickable label on the windows task bar so when clicking it will show a window just like Microsoft Windows Search?
Sounds like you're looking for an "Explorer Band"[^]
I are Troll
|
|
|
|
|
Google for "Windows 7 Taskbar .NET Integration" and you'll find an SDK you can use that might supply what you need.
|
|
|
|