附加数据库后 即可使用
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace 家庭财务管理系统{ public partial class MainForm : Form { public MainForm() { InitializeComponent(); } public static string id = ""; public static string kahao = ""; public static string shijian = ""; public static string jine = ""; public static string leixing = ""; private void label4_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { string num = this.textBox1.Text; string time = this.textBox2.Text; string type = this.textBox4.Text; if (num == "") { MessageBox.Show("银行卡号不能为空"); } else { float money = float.Parse(this.textBox3.Text); if (money < 0) { MessageBox.Show("交易金额必须大于0"); } else { string sql = string.Format("insert into bankCard values('{0}','{1}','{2}','{3}')", num, time, money, type); if (DBHelper.ExecuteNonQuery(sql)) { MessageBox.Show("新增成功"); } string sql1 = string.Format("select * from bankCard "); DataTable dt = DBHelper.GetDataTable(sql1); this.dataGridView1.DataSource = dt; this.textBox1.Text = ""; this.textBox2.Text = ""; this.textBox3.Text = ""; this.textBox4.Text = ""; } } } private void MainForm_Load(object sender, EventArgs e) { string sql = string.Format("select * from bankCard"); DataTable dt = DBHelper.GetDataTable(sql); this.dataGridView1.DataSource = dt; } private void button2_Click(object sender, EventArgs e) { this.textBox1.Text = ""; this.textBox2.Text = ""; this.textBox3.Text = ""; this.textBox4.Text = ""; } private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { id = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); kahao = this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString(); shijian = this.dataGridView1.SelectedRows[0].Cells[2].Value.ToString(); jine = this.dataGridView1.SelectedRows[0].Cells[3].Value.ToString(); leixing = this.dataGridView1.SelectedRows[0].Cells[4].Value.ToString(); UpdateForm update = new UpdateForm(); update.Show(); } private void button3_Click(object sender, EventArgs e) { string sql1 = string.Format("select * from bankCard "); DataTable dt = DBHelper.GetDataTable(sql1); this.dataGridView1.DataSource = dt; } }}
评论