|
I forgot to mention that this is a remote database housed on a SQL 2005 server. It is not local
|
|
|
|
|
It will have to be done sooner or later. Later probably means more code to change, and more data in the tables; so why not do it sooner?
You can automate a lot of it: add a MFG table, and a MFG_ID to existing tables; then write some code to copy MFG_name form existing tables to new MFG table and insert MFG_ID values. All this does not clean the situation, it merely normalizes, and moves the different spellings of HP to the MFG table (all with different IDs).
However you can now list the MFG table, sort it, and start cleaning it (merging different MFG_IDs that should be the same).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Sounds like a great idea! I'm going to start working on that.
Thanks!
|
|
|
|
|
Actually, I am just going to work on doing that. But just for knowledge, would the local database cache in visual studio work for something like this?
|
|
|
|
|
My database experience is limited, so I'm afraid I don't have a clue, except to say that generally caches are meant to speed up things.
You might consider asking in the database forum.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Firstly - do take luc's advice, you need to normalise you database.
Once the database is normalised it then becomes easier to service the combo/auto complete fields because you would now have the concept of Master Tables or Static data.
I am assuming you are using winforms so this is how we do it.
Have a static class called MasterTables with a property for each table that services the combo's. In the getter have it check if a local datatable variable for the table is null and load it if required. This leaves the data in memory on the local machine. If the user adds a record to a master table you set the mastertables property to null and it will automatically be loaded next time it is called.
Caveat, this does NOT refresh master tables modified on other client machines, for that you need to wire up events back to SQL Server. I have never seen a need to do this with the type of apps I write.
|
|
|
|
|
Hey every body, I am just trying to do some application in C#(like to transfer data from 1 pc to another) from my Network knowledge(up to I have learned),If one of the computer is set not accept connections ,it will not accept data transfers or other connections. So while I was trying to connect to the other PC using C# , is there a way to know such kind of problems or is it possible to open the connection ? If there is something wrong on my question please notify me .
Thank you.
|
|
|
|
|
Not able to open connection can be boiled down to configuration.
You usaly connect to specific IP on specific port. Routers, Firewalls and other internet securty solution can result in blocking port and ip if not in their white list.
The other possibilty is the program host or client offline
|
|
|
|
|
So you are saying ....... I just have to write a connection checking code (to check wether or not I am blocked or not by the securities) ..... if not bocked I can write a code to send some data.... Is that write?
|
|
|
|
|
I don't think that is possible. You coud try connecting, if fails you could promp user to check settings
|
|
|
|
|
Saksida Bojan wrote: You coud try connecting, if fails you could promp user to check settings
Errrr....
If he can't connect, how does he prompt the user?
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.”
|
|
|
|
|
I think what he wanted to say was ............ First I try to connect if I cant connect to the pc I can prompt for the user to check connection setting
|
|
|
|
|
This is the C code from MSDN[^]:
typedef struct {
DWORD dwDeltaTime;
DWORD dwStreamID;
DWORD dwEvent;
DWORD dwParms[];
} MIDIEVENT; The problem is with the array as the dwParms field.
If I just want one value, no problem - I just declare the struct like this:
[StructLayout(LayoutKind.Sequential)]
public struct MIDIEVENT
{
public int dwDeltaTime;
private int dwStreamID;
public uint dwEvent;
public uint dwParms;
} ... and it works fine, but when I need an array of uints I can't make it work. If I change the last C# field to
[MarshalAs(UnmanagedType.ByValArray)]
public uint[] dwParms; then it works fine but only gets the first element. If I specify a SizeConst then I can get all the values fine, but I have no way of knowing how many elements there will be at compile time.
Help!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi Dave,
sorry for the delay.
I haven't done this with a variable length array, I have some experience with ByValArray for fixed lengths, with SizeConst.
What you always can do is forget about the struct, just allocate an actual array (either int or uint, whatever suits best) with the right element count to contain the three individuals and the embedded array.
Then use GCHandle to pin it and get its IntPtr, and pass that. That is the way that always works, and never copies any data. BTW: don't forget to free the GCHandle when done.
I hope the native side will somehow figure out the length of the embedded array, and not read/write outside it.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Luc Pattyn wrote: sorry for the delay
10 minutes... you are slacking Luc!
Cheers mate - that worked. I owe you a or ten someday.
What are the pro's and cons of copying data to unmanaged memory vs pinning in managed memory in your opinion?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
pro GCHandle:
- avoids copying, which doubles the memory load, and trashes the cache.
- pinned arrays are read/write, they pass data both ways.
- you can free the GCHandle much later (when all the native stuff is done dealing with the array, could be more than one native call there, even async stuff).
- conceptually simpler than a lot of the Marshal stuff
contra GCHandle:
- unknown cost, assumed irrelevant for large arrays (I often do megabytes of image data)
- pinned means GC can't move, however >80KB is large-object heap anyway, and that one never(hardly ever?) compacts (that is bad in general, not due to GCHandle).
- needs more code in simple cases
- coder is responsible for freeing (I have an LP_Pinner class that implements IDisposable, hence using construct). See TrayIconBuster article.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Just a quickie Luc, If I have a struct instance that is pinned for use in a function, and that struct has an IntPtr as a field, is there any need to pin the field, or is that taken care of automatically by pinning the struct?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I don't expect automatic recursion to occur on pinning; IMO it is your responsibility to make sure somehow that all managed objects are immobilized for as long as your native code uses pointers to them.
I actually hope pinning isn't using any reflection to figure what is inside the object.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Makes sense. I didn't want to unnecessarily replicate something that may have already been done by the system.
Luc Pattyn wrote: I actually hope pinning isn't using any reflection to figure what is inside the object.
Me too, but I don't think so...
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
DaveyM69 wrote: [MarshalAs(UnmanagedType.ByValArray)]
public uint[] dwParms;
You should specify SizeConst parameter for MarshalAsAttribute.You should declare your problematic field as IntPtr,if you don't know the array size.This I wrote this too into your thread before few days.When you get pointer to your struct use Marchal.Copy to copy the data to managed array.See this sample.
Life is a stage and we are all actors!
|
|
|
|
|
The size isn't known until runtime and varies hugely. I tried several different ways using an IntPtr but the data was not correct on the receiving end (a MIDI device). In fact, with the same data in, the output was different each time so I assume the pointer address was getting stored rather than the data itself!
The MIDIHDR structure takes an IntPtr in one field to the data - this data can be one or an array of MIDIEVENTs which contains the unspecified length array.
Luc's suggestion of converting the stuct to a uint[] as a whole instead of just that one field, pinning that and sending the IntPtr of the pinned array to the field in the MIDIHDR works though
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I know you know this Dave - this is purely for anybody who's reading this thread who doesn't know about the SizeParamIndex parameter. This parameter (when applied in a MarshalAs(UnmanagedType.LPArray ), points to the field in the structure that has the size of the returned array.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I'm one of those "anybody who's reading this thread who doesn't know about the SizeParamIndex parameter".
Thanks for the info, and BTW I hope I'll never need it...
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Luc Pattyn wrote: Thanks for the info, and BTW I hope I'll never need it...
No probs. I'm a lot more awake tonight.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I hadn't come accross that one Pete
It doesn't help with this problem as the size (in bytes) of the uint array is held in the lower 24 bits of the uint that is the previous field. Whoever came up with that idea wants shooting!
They could have had the upper 8 bits of the other field as a separate byte parameter for the flags it relates to, and kept a field purely for the size of the array... it would have used just one extra byte of memory per struct when each struct can be thousands of bytes long already so not much difference
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|