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

📄 xuejiguanli.cs

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

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

        private void xuejiguanli_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“mystuInfoDBDataSet2.pro”中。您可以根据需要移动或移除它。
            this.proTableAdapter.Fill(this.mystuInfoDBDataSet2.pro);
            // TODO: 这行代码将数据加载到表“mystuInfoDBDataSet1.xueji”中。您可以根据需要移动或移除它。
            this.xuejiTableAdapter.Fill(this.mystuInfoDBDataSet1.xueji);
            txt_sid.Text = dataGridView1.Rows[0].Cells[0].Value.ToString();
            txt_proname.Text = dataGridView1.Rows[0].Cells[1].Value.ToString();
            txt_grade.Text = dataGridView1.Rows[0].Cells[2].Value.ToString();
            txt_class.Text = dataGridView1.Rows[0].Cells[3].Value.ToString();
        }

        private void btn_changePro_Click(object sender, EventArgs e)
        {
            txt_proname.Hide();
            cb_proname.Show();
        }

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

        private void btn_save_Click(object sender, EventArgs e)
        {
            string cmdstr;
            cmdstr = "update xueji set proname='" + cb_proname.Text +
                   "',grade='" + txt_grade.Text +
                   "',class='" + txt_class.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(cmdstr);
                MessageBox.Show("请重新检查输入和数据库连接!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            finally
            {
                myconnection.Close();
                this.Validate();
                this.xuejiBindingSource.EndEdit();
                this.xuejiTableAdapter.Update(this.mystuInfoDBDataSet1.xueji);
                tableRefresh();
            }
        }
        private void tableRefresh() //刷新表内数据
        {
            this.xuejiTableAdapter.Fill(mystuInfoDBDataSet1.xueji);
        }
    }
}

⌨️ 快捷键说明

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