scholastic/Form5_2.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace scholastic
{
public partial class Form5_2 : Form
{
DataTable mytable;
SqlConnection mycon;
string pstr;
public Form5_2()
{
InitializeComponent();
}
private void Showdata()
{
string constr = "server=.\\sql2005;database=mydata;uid=sa;pwd=sa";
mycon = new SqlConnection(constr);
string mysql = "select * from major";
SqlDataAdapter myada = new SqlDataAdapter(mysql, mycon);
mytable = new DataTable();
myada.Fill(mytable);
dataGridView1.DataSource = mytable.DefaultView;
mycon.Close();
}
private void Form5_2_Load(object sender, EventArgs e)
{
Showdata();
textBox1.Text = mytable.Rows[0][0].ToString(); //赋值
textBox2.Text = mytable.Rows[0][2].ToString();
textBox3.Text = mytable.Rows[0][3].ToString();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
{
MessageBox.Show("修改数据记录信息不完整,请重新登录!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
mycon.Open();
string myupdate = "update major set 所在系='" + textBox1.Text + "',人数=" + Convert.ToInt32(textBox2.Text) + ",辅导员='"+ textBox3.Text + "' where 专业='" + pstr+"'";
SqlCommand mycom = new SqlCommand(myupdate, mycon);
mycom.ExecuteNonQuery();
mycon.Close();
mycon.Dispose();
Showdata();
MessageBox.Show("已成功修改该条数据库记录信息!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
后面还有 19 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读 AI
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
