当用户在C#中进行编辑时,创建一个日志.txt文件 [英] Make a log .txt file when user edits in C#

查看:117
本文介绍了当用户在C#中进行编辑时,创建一个日志.txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我想让用户所做的所有更改都显示在txt文件中.
如果用户对我的数据库进行了添加/修改/删除的更改,并且我想知道我想要一个按钮,并且如果单击了该按钮,则应该有一个包含信息的txt文件.

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.

推荐答案

好吧,这段代码是没有用的.将您的日志创建为字符串,然后使用File.WriteAllText将其写在一行中.
Well, this code is useless. Create your log as a string then use File.WriteAllText to write it in one line.


除非我丢失了某些内容,否则这里有2个独立的问题.如果我误解了,请纠正我或更好地解释.

1)在用户编辑时,您需要保存更改列表.您打算在哪里保存?在文本文件中?每次都应该覆盖还是附加?文件应允许多大?更改应该保存在数据库中吗?首先,您需要决定.

2)您想知道通过按按钮进行了哪些更改.在按钮按下事件中,您将提取用户编辑时保存的信息,然后将其呈现在文本控件中.一旦决定了第一部分的操作方式,然后只需保存您保存的文本并将其放入文本框控件即可,这应该很简单.

第一部分的操作方式取决于用户用来编辑数据库的控件.我经常使用具有检查更改记录的表单.在Enter事件处理程序中,保存旧数据,然后在控件的Validate事件处理程序中检查它是否已更改,并在决定保存的位置保存信息.

祝你好运!
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!




要将数据库中所做的所有更改都保存到一个文件中,您需要执行两个步骤(尽管我不建议这样做).

首先,您需要创建一个触发器以在单独的Table(LogTable)中写入日志.然后使用 BCP [
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


这篇关于当用户在C#中进行编辑时,创建一个日志.txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆