Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 30-Aug-12 11:14am
Comments
Wes Aday at 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");

}
RuanSmit at 30-Aug-12 17:41pm
   
i struggle with how to save or where to save the activity of the user?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Well, this code is useless. Create your log as a string then use File.WriteAllText to write it in one line.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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!
  Permalink  
Comments
Marcus Kramer at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 30 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100