C#操作数据库基础实例《密码管理工具》
近来接触到C#语言,感觉到很强大,参照浪曦密码管理和北风网的家庭理财案例,写了一个最为基础的C#操作数据库实例,做了详细的注释作为备忘,也供初哥参考,高手就莫看了。
先贴界面:
主窗体源代码
view plainusing 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;
using System.IO;
using System.Data.OleDb;
namespace PassMan
{
public partial class PassMan : Form
{
public PassMan()
{
InitializeComponent();
//初始化加载皮肤
skinEngine1.SkinFile = "MacOS.ssk";
}
private void PassMan_Load(object sender, EventArgs e)
{
string sql = "Select * from passMan";
Bind(sql);
//实现隔行变色
dataGridView1.RowsDefaultCellStyle.BackColor = Color.White;
dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Gainsboro;
}
internal void Bind(string sql)//此处声明为internal级别,引用类中才能使用该方法
{
dataGridView1.DataSource= DBHelper.GetDataSet(sql);
//自定义dataGridView的表头以及列宽
dataGridView1.Columns[0].HeaderText = "序号";
dataGridView1.Columns[1].HeaderText = "标题";
dataGridView1.Columns[2].HeaderText = "网址";
dataGridView1.Columns[3].HeaderText = "用户名";
dataGridView1.Columns[4].HeaderText = "密码";
dataGridView1.Columns[5].HeaderText = "更新日期";
dataGridView1.Columns[0].Width = 52;
dataGridView1.Columns[1].Width = 85;
dataGridView1.Columns[2].Width = 175;
dataGridView1.Columns[3].Width = 75;
dataGridView1.Columns[4].Width = 75;
dataGridView1.Columns[5].Width = 120;
toolStripStatusLabel1.Text = "共有" + (dataGridView1.RowCount).ToString() + "条记录。";
}
private void PassMan_FormClosed(object sender, FormClosedEventArgs e)// 重载窗体退出事件,因为splash窗体是本窗体的父窗体,所以不会随本窗体关闭而退出程序
{
Application.Exit();
}
private void 查询ToolStripMenuItem_Click(object sender, EventArgs e)
{
Search sch = new Search();
//实现查询窗体中操做本窗体的可用方法
sch.ipassMan = this;
sch.Show();
}
private void 添加ToolStripMenuItem_Click(object sender, EventArgs e)
{
AddForm add = new AddForm();
//实现添加窗体中操做本窗体的可用方法
add.ipassMan = this;
add.Show();
}
private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
{
ModifyForm mod = new ModifyForm();
//实现修改窗体中操做本窗体的可用方法
mod.ipassMan = this;
mod.Show();
}
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
string message = "您确实要删除选定记录吗?";
string caption = "删除提醒";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
result = MessageBox.Show
补充:软件开发 , C# ,