|
suppose I have the code was inserting records into the file c: \ \ test.dat see the code http://www.koders.com/csharp/fid4FB06ED9F7F6AA6BB805F9152B3DB29BBD1D0C61.aspx?s = CDEF% 3Afile
ith now want to delete the records in the file c: \ \ test.dat I can copy the code
btnAppend_Click to delete sample letter how i
code:
'Add items
private void btnAppend_Click (object sender, System.EventArgs e)
{
....
sf.Open (System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.None);???
...
}
'Delete the ith sample
private void btnDelete_Click (object sender, System.EventArgs e)
{
....
sf.Open (System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.None);???
...
}
|
|
|
|
|
The steps are generally pretty simple. Read the file in, and look for the record you want to delete. Delete the record. Save the file back out.
What, exactly, are you having trouble with?
|
|
|
|
|
Looks like a spooky way to serialize something. I suggest you use a BinaryFormatter , and use a Collection to manipulate the data.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
for example: add, delete, edit, ... struct binary record form and load the data into the listview? I'm using C # 2005, if you share yourself with, thank you
|
|
|
|
|
Same way as for a text file.
1. Open file
2. Read to just before place you want to delete.
3. Mark that spot - call it A.
4. Read to just after you want to delete.
5. Keep reading but as you read write back to position A (incrementing A as you go of course.)
6. Keep going until you reach the end of the file.
|
|
|
|
|
I would like to know when a program was installed on a remote machine.
I can read HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\[XXXXXXX] remotely, but I can't seem to translate the UninstallString into a date remotely via MSIGetProductInfo, so I then tried to see if I could read the keys last modified date via RegEnumKeyEx and did not have success there either. If anyone knows how to do this, I would be very appreciative, I cannot find a single working example of RegEnumKeyEx so that I can plug in a server name, hive, path and key name to test with.
Thank you for reading.
|
|
|
|
|
Here is the function I ended up writing for this in case this comes up in a search. Future readers ... any questions, just ask
[DllImport("Advapi32.dll", EntryPoint = "RegEnumKeyExW")]
private static extern int RegEnumKeyEx(
UIntPtr hKey,
int dwIndex,
[MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpName,
ref int lpcName,
int lpReserved,
int lpClass,
int lpcClass,
[MarshalAs(UnmanagedType.Struct)] out System.Runtime.InteropServices.ComTypes.FILETIME lpftLastWriteTime
);
public static string reg64readerModifiedDate(string serverName, string hive, string keyPath, string stringValue)
{
uint hiveConst = HKEY_LOCAL_MACHINE;
switch (hive)
{
case "hkcr":
hiveConst = HKEY_CLASSES_ROOT;
break;
case "hkey_classes_root":
hiveConst = HKEY_CLASSES_ROOT;
break;
case "HKCR":
hiveConst = HKEY_CLASSES_ROOT;
break;
case "HKEY_CLASSES_ROOT":
hiveConst = HKEY_CLASSES_ROOT;
break;
case "hkcu":
hiveConst = HKEY_CURRENT_USER;
break;
case "hkey_current_user":
hiveConst = HKEY_CURRENT_USER;
break;
case "HKCU":
hiveConst = HKEY_CURRENT_USER;
break;
case "HKEY_CURRENT_USER":
hiveConst = HKEY_CURRENT_USER;
break;
case "hklm":
hiveConst = HKEY_LOCAL_MACHINE;
break;
case "hkey_local_machine":
hiveConst = HKEY_LOCAL_MACHINE;
break;
case "HKLM":
hiveConst = HKEY_LOCAL_MACHINE;
break;
case "HKEY_LOCAL_MACHINE":
hiveConst = HKEY_LOCAL_MACHINE;
break;
case "hku":
hiveConst = HKEY_USERS;
break;
case "hkey_users":
hiveConst = HKEY_USERS;
break;
case "HKU":
hiveConst = HKEY_USERS;
break;
case "HKEY_USERS":
hiveConst = HKEY_USERS;
break;
case "hkcc":
hiveConst = HKEY_CURRENT_CONFIG;
break;
case "hkey_current_config":
hiveConst = HKEY_CURRENT_CONFIG;
break;
case "HKCC":
hiveConst = HKEY_CURRENT_CONFIG;
break;
case "HKEY_CURRENT_CONFIG":
hiveConst = HKEY_CURRENT_CONFIG;
break;
case "hkdd":
hiveConst = HKEY_DYN_DATA;
break;
case "hkey_dyn_data":
hiveConst = HKEY_DYN_DATA;
break;
case "HKDD":
hiveConst = HKEY_DYN_DATA;
break;
case "HKEY_DYN_DATA":
hiveConst = HKEY_DYN_DATA;
break;
case "hkpd":
hiveConst = HKEY_PERFORMANCE_DATA;
break;
case "hkey_performance_data":
hiveConst = HKEY_PERFORMANCE_DATA;
break;
case "HKPD":
hiveConst = HKEY_PERFORMANCE_DATA;
break;
case "HKEY_PERFORMANCE_DATA":
hiveConst = HKEY_PERFORMANCE_DATA;
break;
default:
MessageBox.Show("Default");
break;
}
UIntPtr key = new UIntPtr(hiveConst);
IntPtr remKey;
int ret = RegConnectRegistry(serverName, key, out remKey);
UIntPtr remKeyUIntPtr = unchecked((UIntPtr)(long)(ulong)remKey);
string result = GetRegKey64DWord(remKeyUIntPtr, keyPath, RegSAM.WOW64_64Key, stringValue);
uint lpcbData = 1024;
StringBuilder strBuffer = new StringBuilder(1024);
int dIndex = 0;
int lpcName = 1024;
int lpClass = 1024;
int lpcClass = 1024;
System.Runtime.InteropServices.ComTypes.FILETIME lpftLastWriteTime = new System.Runtime.InteropServices.ComTypes.FILETIME();
RegEnumKeyEx(remKeyUIntPtr, dIndex, strBuffer, ref lpcName, 0, 0, 0, out lpftLastWriteTime);
long hFT2 = (((long)lpftLastWriteTime.dwHighDateTime) << 32) + lpftLastWriteTime.dwLowDateTime;
DateTime dt = DateTime.FromFileTime(hFT2);
RegCloseKey(remKey);
result = dt.ToString();
return (result);
}
|
|
|
|
|
You could remove half of those case s by normalizing the capitalization. Do a ToUpper and the code will be a bit smaller/easier to read.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
That's a great point, I am going to clean up the code soon and that is one of the first things I'll do
|
|
|
|
|
Hi experts,
i want to display data in gridcontrol like all columns headings should be named as given date range daily, weekly and monthely. in each row data should display against each date with each id number of employee.
thanks
|
|
|
|
|
So what is your question?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Yes it can be done!
But you need to expand / explain your problem, what you have tried or even show code detailing where its going wrong and detailing as much as you can and include errors where possible.
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
ok thanks.
actually i didn't build yet therefore i can't provide code.
i want to build. i am trying to build 20 employees duty and want to see their roster in gridcontrol.
all employees section wise or id wise should display left side of the grid date range should display on columns headings and employees duty timinges should appear in cells all these should be from access database table.
|
|
|
|
|
Okay, so when you've built some of it, feel free to pop back with any questions on the code you've written - we'll be glad to help you fix things.
|
|
|
|
|
hi guys . i have asked my qustion in algorithm section but no one have respond me . i'll appriciate for any help .
my qustion is that , i have made a bfs solver class that solve the puzzle 8 with bfs algorithm .
what im doing its like this .
1 - node class >> contain some info
2- bfs solver class
2-1 : Qeue Neede .
2-2 : enqeue the first node (initial state) << its parent .
2-3 : check if its the Goal Or not (if its not go to next )
2-4 : find the empty tile and see if you can exchange any tile with it .
2-5 : any change w'll make a child node . of that parent
2-6 : deqeue the parent node.
2-6 : check if the child node of the parent is in the qeue (if is not then enqeue the child node and put a parent label on it). jump to the (2-3)
is that algorithm working well , i have test it and it really work fine , the problem its here that it dosnt work if i played too much with the tile and chaneged them around . it works fine in small problem like {1,2,3,5,4,6,0,7,8} or sth like this .
and it gave me an error stackoverflow in big problems like {8,0,4,2,3,1,6,7,5} i dont know what should i do to prevent this error but i just know that my codes work fine .
im writing my code with c#.net . using a node class and bfs solver class.
i can put some parts of my code if you neede to see what im doing .
i'll appriciate any help .
|
|
|
|
|
You are talking about the brute force search, aren't you?
mohammadkaab wrote: it gave me an error stackoverflow in big problems like {8,0,4,2,3,1,6,7,5}
It's implemented recursivly?!
You have to test, wether a state has already been calculated or not, otherwise you get an infinite loop and a stackoverflow!
------------------------------
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
ofcourse im doing this , i'll check if the current node it has been in the qeue or not , if its in the qeue then i'll ignore and go to the next part .
but a fellow in the algorithm section give me a soluation that i cant find out what that supose to mean .
fellow in algorithm section said :
The problem is that breadth-first search (bfs) tries ALL sequences of length N before it tries any of length N+1. And it stores all these intermediate attempts, resulting in your stack overflow for a deep solution.
An approach more specific to the problem would give better results, e.g.
for (int tile = 0; tile <= 8; ++tile)
placeTileInCorrectPosition (tile, board);
"Microsoft -- Adding unnecessary complexity to your work since 1987!"
i dont know what does that mean .
|
|
|
|
|
mohammadkaab wrote: breadth-first search
Ahh! Breadth-First Search!
Yes, that is... no solution. Because in every turn it increases exponential. The only way is another algorithm:
depth-first search or (even better) A* search<
------------------------------
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
mohammadkaab wrote: i have asked my qustion in algorithm section but no one have respond me
The forums are international. You have to have patience - the person who can answer your question may be asleep or at work. As we don't get paid for helping out, we get to answering questions when we can.
Second point - I found your question difficult to read, not because English isn't your first language, but because you don't use capitals. Please, at the start of a sentence, use some capitals.
|
|
|
|
|
Hi
I have a situation where we have an application that we have written and a third party application. Basically when a change happens in the 3rd party SQL database, we want to make changes to our own SQL database.
What would be the best way to achieve this? Obviously a combination of SQL triggers/stored procedures could achieve this, but was wondering if there was another alternative?
Thanks
|
|
|
|
|
UCLAdam wrote: Obviously a combination of SQL triggers/stored procedures could achieve this, but was wondering if there was another alternative?
There are other ways, but to use triggers/stored procedures is the best.
------------------------------
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
Thanks ihoecken. I thought that might be the case. Out of interest what are the other ways?
|
|
|
|
|
UCLAdam wrote: Out of interest what are the other ways?
Well depending on the situation.
- Replication - if just data has to be transfered
- adding a "sync" column in the tables, but then the 3rd-party solution has to clear it when it changes or add a column - otherwise triggers would be needed
------------------------------
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
It really depends on what changes you want to make, and when you want to make those changes. You could do this with triggers, but that would mean modifying the 3rd party database, and you could have issues if you change the schema of the 3rd party database (say during an update). Also, some 3rd parties will have warranty/support clauses that would be invalidated by you altering their schema - we do, for instance, because of a particularly troublesome client who broke the database and then expected us to bail them out at our expense.
If you are just looking to replicate the data, and the change doesn't need to be instantaneous, you could use something like the Sync Framework[^] to accomplish this.
BTW - this isn't a C# question. It belongs in the database forum.
|
|
|
|
|
Thanks Pete. Unfortunately the changes do need to be instantaneous and we need to manipulate the data before putting it into our database. Luckily we are able/allowed to change the 3rd party DB schema, but obviously have to bear updates in mind like you say.
Apologies for posting in wrong forum, you're completely right. May be I was subconsciously hoping for a C# solution!
|
|
|
|
|