2024年3月9日发(作者:)
C#操作Access的查
询、添加、删除、修改
源程序
-CAL-FENGHAI-(2020YEAR-YICAI)_JINGBIAN
using System;
using ;
using ;
using ;
using ;
using ;
using Location
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
= "Location System";
= "连接数据库";
= "查询";
= "退出";
= "添加";
= "删除";
= "修改";
= "ID:";
= "0";
}
private void button1_Click(object sender, EventArgs e)
{
string ConStr = "Provider= source=";ext);
OleDbCommand cmd = new OleDbCommand("Select * From data where
ID>=@id", con);
"@id",i);
OleDbDataReader reader = ();
();
oString();
= reader[1].ToString();
= reader[2].ToString();
= reader[3].ToString();
= reader[4].ToString();
= reader[5].ToString();
= reader[6].ToString();
();
();
}
private void button4_Click(object sender, EventArgs e) //添加
{
string ConStr = "Provider= source=";//创建OleDbConnection对象
OleDbConnection con = new OleDbConnection(ConStr);
();
for (int i = 0; i < 1000; i++)
{
string sql = "insert into data(ID)values(" + i + ")";
OleDbCommand cmd = new OleDbCommand(sql, con);
();
}
();
}
private void button5_Click(object sender, EventArgs e) //删除
{
string ConStr = "Provider= source=";//创建OleDbConnection对象
OleDbConnection con = new OleDbConnection(ConStr);
();
OleDbCommand cmd = new OleDbCommand("delete from data", con);
();
}
private void button6_Click(object sender, EventArgs e) //修改
{
string ConStr = "Provider= source=";//创建OleDbConnection对象
OleDbConnection con = new OleDbConnection(ConStr);
();
string sql = "update data set longitude=12 where ID=1";
OleDbCommand cmd = new OleDbCommand(sql, con);
();
}
}
}


发布评论