⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 praiseandpunish.cs

📁 利用vs2008+sql2000开发的小型学生信息系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace StudentInfoMS
{
    public partial class praiseandpunish : Form
    {
        string connstr = "Data Source=localhost;Initial Catalog=mystuInfoDB;Integrated Security=True";
        public praiseandpunish()
        {
            InitializeComponent();
        }

        private void praiseandpunish_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“mystuInfoDBDataSet3.beizhu”中。您可以根据需要移动或移除它。
            this.beizhuTableAdapter.Fill(this.mystuInfoDBDataSet3.beizhu);

        }

        private void btn_reset_Click(object sender, EventArgs e)
        {
            txt_sid.Text = null;
            txt_praise.Text = null;
            txt_punish.Text = null;
            txt_beizhu.Text = null;
            txt_sid.Focus();
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            txt_sid.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0].Value.ToString();
            txt_praise.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[1].Value.ToString();
            txt_punish.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[2].Value.ToString();
            txt_beizhu.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[3].Value.ToString();
        }

        private void btn_save_Click(object sender, EventArgs e)
        {
            string cmdstr;
            cmdstr="update beizhu set praise='"+txt_praise.Text+"',"+
                   "punish='"+txt_punish.Text+"',"+
                   "beizhu='"+txt_beizhu.Text+"'"+
                   " where sid='"+txt_sid.Text+"'";
            SqlConnection myconnection = new SqlConnection(connstr);
            SqlCommand sqlcmd = new SqlCommand(cmdstr,myconnection);
            try
            {
                myconnection.Open();
                int row= sqlcmd.ExecuteNonQuery();
                myconnection.Close();
                if (row == 0)
                {
                    MessageBox.Show("请重新检查输入和数据库连接!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("请重新检查输入和数据库连接!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            finally
            {
                myconnection.Close();
                tableRefresh();
            }
        }
        private void tableRefresh() //刷新表内数据
        {
            this.beizhuTableAdapter.Fill(mystuInfoDBDataSet3.beizhu);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -