Visual Studio 2022 简易项目实操[四]-数据优化篇

新增需求

删除日志也可以点击页面查看

如下

图片[1]-Visual Studio 2022 简易项目实操[四]-数据优化篇-岸边IBIAN

实操

1、新增button控件,并设置TEXT 名称为删除日志查询

2、显示控件利用dataGridView来显示

3、查询绑定requestid

private void button2_Click(object sender, EventArgs e)
{
    string requestId = textBox1.Text.Trim(); // 获取请求ID

    if (!string.IsNullOrEmpty(requestId))
    {
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            connection.Open();

            string selectLogQuery = @"
                SELECT RecordId, OperationType, OperatedDate, OperateTime, OperatedBy, ClientIp 
                FROM LimitoperationLog 
                WHERE TableName = 'workflow_requestlog' AND OperationType = 'Delete' AND requestid = @requestId
                ORDER BY OperatedDate DESC, OperateTime DESC";

            using (SqlCommand command = new SqlCommand(selectLogQuery, connection))
            {
                command.Parameters.AddWithValue("@requestId", requestId);
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                DataTable dataTable = new DataTable();
                adapter.Fill(dataTable);

                dataGridView1.DataSource = dataTable; // 假设dataGridView1是用来显示日志数据的DataGridView控件
            }
        }
    }
    else
    {
        MessageBox.Show("请输入请求ID!");
    }
}
图片[2]-Visual Studio 2022 简易项目实操[四]-数据优化篇-岸边IBIAN
THE END
点赞12赞赏 分享
抢沙发
头像
提交
头像

昵称

取消
昵称表情

    暂无评论内容