Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C#表单应用程序中记录用户活动_C#_Logging - Fatal编程技术网

在C#表单应用程序中记录用户活动

在C#表单应用程序中记录用户活动,c#,logging,C#,Logging,在我的表单应用程序中,我有两个按钮。当用户点击按钮时,它会在SQL中更新 因此,我想将用户在文本框中输入的数字记录在单独的txt文件中(记录用户在表中输入的内容) 请检查以下代码以取消订阅以及我的应用程序正在执行的操作 private void button_StatusChange_Click(object sender, EventArgs e) { SqlConnection sqlcon = new SqlConnection("Data source = Test; Initi

在我的表单应用程序中,我有两个按钮。当用户点击按钮时,它会在SQL中更新

因此,我想将用户在文本框中输入的数字记录在单独的txt文件中(记录用户在表中输入的内容)

请检查以下代码以取消订阅以及我的应用程序正在执行的操作

private void button_StatusChange_Click(object sender, EventArgs e)
{
    SqlConnection sqlcon = new SqlConnection("Data source = Test; Initial Catalog = TableName; user id = sa;pwd = 12345678 ");
    if (MessageBox.Show("Do you really need to change", "Success", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
        this.Close();

    SqlCommand updateCommand = sqlcon.CreateCommand();
    sqlcon.Open();
    updateCommand.CommandText = " update dbo.TableTBL set ColumName = '" + comboBox_statusChange.Text + "' where TId = '" + textBox_cNumber.Text + "'";

    string resultStatus = ((string)updateCommand.ExecuteScalar());
    updateCommand.ExecuteScalar();
    MessageBox.Show(" Status Changed Successfully");
    sqlcon.Close();

}

没有注意到您的问题我想启用登录我的用户活动,例如文本框中的数字您是指“文本框\u cNumber”中的值吗?在文本框中输入的客户应该登录到文本文件中您没有名为
TableTBL
的表,是吗?这不起作用
File.Create
将创建该文件并返回一个
FileStream
,您可以使用它对该文件执行操作,但不会关闭。所以下一行会出现IOException。您只需要
文件。AppendAllText
行->它为您创建文件,您不需要调用
文件。Create
。非常感谢,Arran!没有正确地测试它。固定的。
//very simple log to file
File.AppendAllText("filepath_here.txt", DateTime.Now.ToString(CultureInfo.InvariantCulture) + " " + textBox_cNumber.Text + "\r\n");