Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
ok so i want to get all changes made by a user to be showed in a txt file.
if a user makes changes to my database add/modify/delete and i want to know i want a button and if its clicked there should be a txt file with info in it.

public log()
{
initialized component
}

private string log

private void btnLog(object sender, EventsArgs e)
{
StreamWriter sw = new StreamWriter(@"",true)
{
 

}
}


thats what i have i cant seem to figure out to do it.
Posted
Comments
[no name] 30-Aug-12 17:21pm    
What exactly is it that you "cant seem to figure out"?
StreamWriter sw = new StreamWriter(@"log.txt",true)
{
sw.Write("Whatever you want to log");

}
[no name] 30-Aug-12 17:41pm    
i struggle with how to save or where to save the activity of the user?

Well, this code is useless. Create your log as a string then use File.WriteAllText to write it in one line.
 
Share this answer
 
Unless I'm missing something, you have 2 separate issues here. Correct me or explain better if I misunderstood.

1) While a user is editing, you need to save a list of changes. Where do you plan to save that? In a text file? Should it be overwritten each time or appended? How large should the file be allowed to get? Should the changes be saved in your database? First you need to decide that.

2) You want to know what changes are made by pressing a button. In the button press event, you would extract the information saved when the user edited, then present it, perhaps in a text control. Once you decide how to do the first part, then simply get the text you saved and put it into a text box control and that should be simple.

How you do the first part will depend on what controls the user uses to edit your database. I often use a Form that has checks for changes records. In the Enter event handler, save the old data, then in the Validate event handler of the control check whether it changed and save the information wherever you decide to save it.

Good luck!
 
Share this answer
 
Comments
fjdiewornncalwe 30-Aug-12 19:23pm    
OP's answer: @Walt Fair, Jr
i want it simple, if a user made changes in database its saves the username, date/time , what did they do. its only for experiment purposes so it wouldn't be that big and wont be necessary to be overwritten. the .txt file should just be saved in my documents.
Hi,

To get all the changes made in the database into a file you need to follow two steps(Although i am not recommend it.)

First of all you need to create a trigger to write log in separate Table(LogTable). and then using BCP[^] command you can extract your Table log into CSV data file in specified folder. You can create an XML/TXT/CSV file from your Log data.

My suggestion is you can keep your database log in database itself. why you want it in separate file? Even if you can read from database.


Hope i answered your query
Thanks
-Amit Gajjar
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900