|
Hi Luc
Luc Pattyn wrote: ToString() shows the data formatted like the user (you) said he wanted it, see the Control Panel ("Regional Settings" or "Dates and Times")
Now I got you (little did I know).
Turned out I forgot that MS Access uses the JET engine. That's what happens when you leave a gap between researching what database to use and the actual implementation. At http://technet.microsoft.com/en-us/library/cc966377.aspx, I found the following:
Note that this date literal must always be expressed in MM/DD/YY order. To avoid the ambiguity of the meaning of stored queries, Microsoft Jet doesn't follow the international date format settings specified in the user's Control Panel.
So, given my example given earlier, all I needed to do was:
"SELECT * FROM MyTable WHERE someDate = #7/6/10#"
As I understand now, it would be better to work with DateTime types in the implementation, and convert them to properly formatted Strings in queries. Anyway, many thanks for all your effort.
|
|
|
|
|
Dirkus Maximus wrote: Microsoft Jet doesn't follow the international date format settings specified in the user's Control Panel.
That is correct, it holds true for each and every database; databases don't care about human users and their formatting preferences. After all, their data needs to be portable across the world.
Dirkus Maximus wrote: Note that this date literal must always be expressed in MM/DD/YY order.
That is a surprise to me. I have always used yyyy-MM-dd and that has served me well, probably because it is unambiguous and easy to understand, so I suspect the MSDN statement is overly strict, in real life JET seems to accept more than one format.
What remains is your now puzzling statement a date like "15/12/2010" works fine at the end of your very first message in this thread. It clearly follows dd/MM/yyyy which is yet another format, and yet you said it worked well. I don't have an official reference, however some pages (such as this[^] one) claim JET is quite forgiving, but when in doubt looks for m/d/y.
|
|
|
|
|
Hi Dirkus,
I now have expanded a pre-existing article [^]of mine on DateTime, by adding the essentials of what we discussed today. Maybe it is of further interest to you.
|
|
|
|
|
Great article Luc - very informative. I ended up having a DateTime representation of the Date instead of just a String.
DateTime^ dt = gcnew DateTime(yearField, monthField, dayField);
And when I need to insert it in the DB, I use the format you advocate:
String^ query = "INSERT INTO myTable (..., someDateField, ...) Values(..., dt->ToString("yyyy'/'MM'/'dd"), ..."
To retrieve it back, I use what the JET documentation says, i.e. I convert it into the MM/DD/YY form first.
array <String^>^ strArr = fromDate->Split('/');
int dayField = Convert::ToInt32(strArr[0]);
int monthField = Convert::ToInt32(strArr[1]);
String^ yearField = Convert::ToString(strArr[2]);
yearField = yearField->Substring(2,2);
String^ formattedDate = String::Concat(" #",Convert::ToString(monthField),"/", Convert::ToString(dayField),"/", yearField,"# ");
query = "SELECT * FROM myTable WHERE someDate = " + formattedDate + ";
It's all a bit convoluted, but this method is working well now.
I don't know why (as described in my first post) this 'one digit' day didn't work while the '2-digit' one did - though I did forget to mention that I'm using quite an early version of MS Access (2003), so this problem may be fixed by now.
Just one other thing, from an MSDN forum I learned that
JET SQL supports different types. You can declare parameter type by using PARAMETERS clause. The OleDB provider in ADO.Net does not support named parameters.
|
|
|
|
|
Dirkus Maximus wrote: Great article Luc - very informative
Thanks.
Dirkus Maximus wrote: It's all a bit convoluted
Yes it is. I don't understand why you would do inserts and selects differently. The simple
dt->ToString("yyyy'/'MM'/'dd") or dt->ToString("yyyy-MM-dd") should work here too. And you could incorporate the # signs in the format string.
Dirkus Maximus wrote: I don't know why (as described in my first post) this 'one digit' day didn't work while the '2-digit' one did
I have strong doubts your 2-digit dates did work correctly all the time. The way I see it, Access (or ADO.NET) tries to interpret your date literals as mm/dd/yy unless they are clearly something else (as with my yyyy-mm-dd). However as soon as the first number exceeds 12, they understand it can't be mm/dd/yy, so they look for dd/mm/yy and IMO that is why it seemed to work, but not for 1-digit days.
Dirkus Maximus wrote: JET SQL supports different types. You can declare parameter type by using PARAMETERS clause. The OleDB provider in ADO.Net does not support named parameters.
AFAICR I've never seen anyone do Access without OLEDB.
|
|
|
|
|
Luc Pattyn wrote: I don't understand why you would do inserts and selects differently
Yes, I made things much too difficult. There's no need for splitting strings and all that.
When I get a DataType back from the database and need to display it in text, I just go
String^ text = ((DateTime)datarow[4]).ToString("dd MMM yyyy")
And to put a text like the above into a query, I convert it back with
String^ query = "SELECT * FROM myTable WHERE myDate = #" + text + "#)";
Things become embarrasingly clear once you get to see the whole picture
Luc Pattyn wrote: I have strong doubts your 2-digit dates did work correctly all the time
That sounds plausible.
Thanks Luc
modified on Thursday, August 26, 2010 11:05 PM
|
|
|
|
|
Hi,
I am currently working on extending an existing C++ project with new functions. The existing project is made using C++, without using managed variables. I would like to insert some of my function which I have written in C++/CLI, so with managed variables.
Is it possible to declare a managed variable within a class, without making the class a ref class? If I have to make it a ref class it produces a load of errors, as it is connected with parts of existing code that cannot deal with that.
Any ideas would be more than welcome!
Thanks,
Arjen
|
|
|
|
|
Arjen Tjallema wrote: Is it possible to declare a managed variable within a class, without making the class a ref class? If I have to make it a ref class it produces a load of errors, as it is connected with parts of existing code that cannot deal with that.
Any ideas would be more than welcome!
Yes, you can. You need to use a gcroot .
See http://msdn.microsoft.com/en-us/library/481fa11f(VS.80).aspx[^]
|
|
|
|
|
It is possible to recompile native code as managed code. You can build wrapper class to expose unmanaged C++ code in CLI. Then you can use managed infrastructure in your code. Check G. Hogenson "C++/CLI" book.
|
|
|
|
|
Thanks a lot, I'll go find out more about it.
Regards,
Arjen
|
|
|
|
|
hi guys, am having problem with angle rotations..
i already have the formula,
double fangle;
double m_iAngle;
m_iAngle = 45;
POINT centerPt;
centerPt.x = m_nCarX + 161; // which s is the x origin
centerPt.y = y + 52; // which s is the y origin
fangle = m_iAngle / 180. * 3.1415926;
float OrX = (float)(centerPt.x - cos(fangle)*centerPt.x + sin(fangle)*centerPt.y);
float OrY = (float)(centerPt.y - cos(fangle)*centerPt.y - sin(fangle)*centerPt.x);
//tyre spoke
dc.SelectStockObject(GRAY_BRUSH);
dc.SelectObject(m_penTyreSpoke);
for(int count = 0, count < 4, count++){
//spoke1
dc.MoveTo(m_nCarX + 161, y + 52);
dc.LineTo(m_nCarX + 161, y + 41);
}
//see image here:
http://h1.ripway.com/lgmanuel/Imgs/car.png[^]
as you see in the image. the car's tire has only one spoke.
am trying to loop the code to have 4 (four) spokes on my rim by bending the angle 90 DEGREES..
adding a 90 DEGREES on LOOP...
//should look like this images bellow:
http://h1.ripway.com/lgmanuel/Imgs/car-with-rim-spoke.png[^]
help guys.. check the project bellow.. thanks ahead..
http://h1.ripway.com/lgmanuel/VisualCPP/GDICarSample.rar[^]
|
|
|
|
|
Hi,
1.
first of all, are you on the right forum? have you switched from native C/C++ coding to managed C++/CLI coding all of a sudden?
2.
please use PRE tags to show code snippets and do show the relevant code; nobody is going to download a ZIP/RAR file to help you out.
3.
if you want N spokes, your best bet is using a for loop. They are pretty good at executing the same code over and over with a slight twist; and add 90 degrees to the angle each time.
4.
Stop using all those magic constants (180, 3.1415926, 161, 52, 41). Either use a function parameter, use an object property (e.g. drawing size), use an official const such as Math.Pi, or if all else fails provide an actual const yourself. You will get more readable code with fewer errors.
|
|
|
|
|
Hi,
Each time I create a new windows forms application, the resource file that I get was app.rc. How to create and set a .resx as the resource file on my application?
Thanks
|
|
|
|
|
Hello,
I need to generate structs and classes at run time in C#(might be in CLI) managed environment. Suppose I have all data and all data types associated with those data memebers of some class/struct. Now I need to generate structs/classes at runtime and after that I need to map data inside those runtime created structs fields.
e.g I have read data from an XML file i.e BSTR field1,BSTR field2,BSTR field3,BSTR field4,BSTR field5,long field6.
Now I need to create struct at runtime which has sizeof the sum of all fields (which I listed above) and then I can easily access those fields one by one. So that whole complete struct is formed.
How can I solve this problem?
Regards Usman
|
|
|
|
|
glitteringsound wrote: e.g I have read data from an XML file i.e BSTR field1,BSTR field2,BSTR field3,BSTR field4,BSTR field5,long field6
I don't think creating types at runtime is the correct way to do this. You should try to design your types in such a way that it can hold the data coming from XML file.
For the example you have shown, I'd create a class which has a List which can hold all BSTR fields. If datatype of BSTR fields are not primitive, I'd create a separate type for BSTR and keep it in the above said list. Now if you have different data types for fields, you can keep a datatype identifier field which will tell you what type the value should be. This will help you to cast to the correct value before using.
Best wishes,
Navaneeth
|
|
|
|
|
hi guys... when i press enter the app just closes.. how do i make a newline on a edit text field?
what i am trying to do is print whatever is typed on the edit control and show it on the static. i did all that..
the problem is when i try to press the [Enter] on my keyboard, the app just closes, what i want to do is make a 'newline' just like in notepad when i press [Enter]..
i already set the Edit box to multiline, still NO-Go-AMIGO...
need help guys..thanks ahead..
modified on Sunday, August 1, 2010 11:41 PM
|
|
|
|
|
You also need the ES_WANTRETURN style on your control, see here[^] for full details of Edit control windows.
It's time for a new signature.
|
|
|
|
|
FWIW: I'm puzzled by your switch from C/C++/MFC forum to this forum, which is for managed C++, i.e. a C++ dialect that is part of the .NET Framework.
|
|
|
|
|
Hi I am trying to get the IPv6 address for the current adapter in my Vista equalant pc(WIN-PE environment).
Hear is the problem. First i started with WMI class "Win32_NetworkAdapterConfiguration" for setting IPv6 address,subnetlen, gateway and retrieving the IPv6 address,subnetlen, gateway. But I was not able to success in getting and setting those values for ipv6. I used the enable static function in this wmi class. But failed.
Now I this iphelper functions are looks interesting, these functions directly returning the IPv6 address that will solve my problem.
Kindly request all people hear, If any one tried sample code for setting and getting IPv6 address ("Looking only for C++/vc++/win32/same family") using wmi lease share that sample example if possible.
Else please share the example of using this iphelper functions.
Thanks a lot
Haranadh
Nice talking to you. If you judge people, you have no time to love them. -- Mother Teresa
|
|
|
|
|
I know the map file generation on VC6.0 as we need to go to Project Settings->C/C++->Set Debug Info to "Line Numbers Only"
then Go to Link-> Enable "Generate Map file" option and provide file name and add these switches "MAPINFO:LINES" and "MAPINFO:EXPORTS"
Now i`m using VS2008, i`m unable to Generate map file. Could you please help me on that.
Thank you
Live life happily until your last second
|
|
|
|
|
You can do that by /MAP[^] compiler switch.
Best wishes,
Navaneeth
|
|
|
|
|
could you tell me where do i need to add this switch
Live life happily until your last second
|
|
|
|
|
Open the properties window of your project, then the option you are interested in is located in the Debugging section, under Linker
|
|
|
|
|
ya..I`m getting MAP file but there is no line number information. How do i can enable that?
Live life happily until your last second
|
|
|
|
|
I'm afraid, but the compiler support for map files has been reduced; I think that the only chance you have to get the addresses for line-number is through the pdb files. To deal with them you can have a look to:
|
|
|
|
|