怎么用c#控件查询access数据库添加删除
1个回答
展开全部
我使用了控件datagridview,访问sqlite数据库,实现增删改与数据库同步。代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SQLite;
namespace CplusData
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static SQLiteConnection conn = new SQLiteConnection(@"Data Source=F:\Project\Data\test;Version=3;");
SQLiteCommand cmd = new SQLiteCommand("select * from usertab", conn);
SQLiteDataAdapter sda = new SQLiteDataAdapter();
DataSet ds=new DataSet();
private void Form1_Load(object sender, EventArgs e)
{
conn.Open();
sda.SelectCommand = cmd;
sda.Fill(ds,"usertab");
this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = "usertab";
conn.Close();
}
private void button1_Click(object sender, System.EventArgs e)
{
SQLiteCommandBuilder scb = new SQLiteCommandBuilder(sda);
scb.GetUpdateCommand();
sda.Update(ds,"usertab");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询