?? praiseandpunish.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 + -