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.OleDb;
namespace 使用Connection对象链接Access数据库
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MyMusics.mdb";
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
conn.Open();
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM MyMusics";
OleDbDataReader reader = cmd.ExecuteReader();
string data="";
while (reader.Read())
{
data += string.Format("{0}\t\t\t{1}", reader[0], reader[1])+Environment.NewLine;
}
this.textBox1.Text = data;
reader.Close();
}
}
}
}
使用Connection对象链接Access数据库
最新推荐文章于 2024-01-18 16:04:31 发布