在我的表单应用程序中,我有两个按钮。当用户点击按钮时,它会在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();
}
答案 0 :(得分:1)
//very simple log to file
File.AppendAllText("filepath_here.txt", DateTime.Now.ToString(CultureInfo.InvariantCulture) + " " + textBox_cNumber.Text + "\r\n");