信息管理系统
操作方法
- 01
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Sql; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // TODO: 这行代码将数据加载到表“大佬DataSet.Table_1”中。您可以根据需要移动或删除它。 this.table_1TableAdapter.Fill(this.大佬DataSet.Table_1); } string connstr = "Data Source=.;Initial Catalog=大佬;Integrated Security=True"; private void button1_Click(object sender, EventArgs e) { string sql = "insert into Table_1 values('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "')"; SqlConnection conn = new SqlConnection(connstr); SqlCommand comm = new SqlCommand(sql, conn); comm.Connection.Open(); SqlDataAdapter da = new SqlDataAdapter(sql, conn); SqlCommand command = new SqlCommand("select * from Table_1", conn); SqlDataAdapter dan = new SqlDataAdapter("select * from Table_1", conn); DataTable dt = new DataTable(); dan.Fill(dt); this.dataGridView1.DataSource = dt; comm.ExecuteNonQuery(); } private void button2_Click(object sender, EventArgs e) { string check = "update Table_1 ID='" + this.textBox2.Text + "',name'" + this.textBox3.Text + "' sex='" + this.textBox1.Text + "'"; SqlConnection conn = new SqlConnection(connstr); SqlCommand comm = new SqlCommand(check, conn); comm.Connection.Open(); SqlDataAdapter da = new SqlDataAdapter(check, conn); DataTable dt = new DataTable(); da.Fill(dt); comm.Connection.Close(); } private void button3_Click_1(object sender, EventArgs e) { string sql = "insert into Table_1 values('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "')"; SqlConnection conn = new SqlConnection(connstr); SqlCommand comm = new SqlCommand(sql, conn); comm.Connection.Open(); SqlDataAdapter da = new SqlDataAdapter(sql, conn); SqlCommand command = new SqlCommand("select * from Table_1", conn); SqlDataAdapter dan = new SqlDataAdapter("select * from Table_1", conn); DataTable dt = new DataTable(); dan.Fill(dt); this.dataGridView1.DataSource = dt; this.textBox4.Text = dt.Rows[0][0].ToString(); this.textBox5.Text = dt.Rows[0][1].ToString(); //this.label4.Text = dt.Rows[0][3].ToString(); comm.Connection.Close(); } } }