2401_83786250 2024-04-25 19:25 采纳率: 0%
浏览 3

使用ASP.NET用c#写奖学金评选系统,这个是学生登录后进入学生页面点击"我的信息"查看自己详细信息.我用的是SQL server数据库

        if (!IsPostBack)
        {
                DisplayStudentInfo(Request.QueryString["学号"]); ; // 如果未登录,重定向到登录页
        }

private void DisplayStudentInfo(string 学号)
{
string connectionString = "Data Source=localhost;Initial Catalog=奖学金评定系统;Integrated Security=True"; // 连接字符串
string query = "SELECT * FROM Student WHERE 学号 = @StudentID";

        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            using (SqlCommand command = new SqlCommand(query, connection))
            {
                command.Parameters.AddWithValue("@StudentID", 学号);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();

                if (reader.Read())
                {
                    Label1.Text = "学号: " + reader["学号"].ToString();
                    Label2.Text = "姓名: " + reader["姓名"].ToString();
                    Label3.Text = "性别: " + reader["性别"].ToString();
                    Label4.Text = "学院: " + reader["学院"].ToString();
                    Label5.Text = "成绩: " + reader["成绩"].ToString();
                    Label6.Text = "辅导员: " + reader["辅导员"].ToString();
                    Label7.Text = "身份证号: " + reader["身份证号"].ToString();
                }
                else
                {
                    // 如果没有找到学生,显示错误信息或者重定向到错误页面
                    Response.Write("未找到该学生信息。");
                }
            }
        }
    }

img

img


可以帮我看看我的代码该怎么改吗

  • 写回答

2条回答 默认 最新

  • 阿里嘎多学长 2024-04-25 19:54
    关注

    以下内容由CHATGPT及阿里嘎多学长共同生成、有用望采纳:


    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 4月25日

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?