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;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace ConnectionDB
{
public partial class Form2 : Form
{
DataSet ds;
int recordCount;
public Form2()
{
BuildData();
BindData();
recordCount = this.BindingContext[ds, "StudentInfo"].Count;
}
private void BuildData()
{
string constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\\C#实验\\ConnectionDB\\Database2.accdb";
string str = "select * from [StudentInfo]";
OleDbConnection conn = new OleDbConnection(constr);
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(str, conn);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
ds = new DataSet();
adapter.Fill(ds, "StudentInfo");
}
private void BindData()
{
this.textBox1.DataBindings.Add(new Binding("Text", ds, "StudentInfo.SNo"));
this.textBox2.DataBindings.Add(new Binding("Text", ds, "StudentInfo.Class"));
this.textBox3.DataBindings.Add(new Binding("Text", ds, "StudentInfo.SName"));
this.textBox4.DataBindings.Add(new Binding("Text", ds, "StudentInfo.Sgrade"));
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.BindingContext[ds, "StudentInfo"].Position -= 1;
}
private void button3_Click(object sender, EventArgs e)
{
this.BindingContext[ds, "StudentInfo"].Position -= 1;
}
}
}
慕标琳琳
相关分类