本人寫了一個簡單的單表數據編輯程序,分為兩層(界面層和數據訪問層)
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
ReportData;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
namespace
ReportApp
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
/**//// <summary>
/// 界面層
/// </summary>
public partial class Form4 : Form
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
private Customer m_Customer = new Customer();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
public Form4()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
InitializeComponent();
bindingSource1.DataSource = m_Customer.GetCustomer();
bindingSource1.DataMember = "dsCustomer";
this.DataBind();
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
public void DataBind()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
txtCustomerCode.DataBindings.Add("Text", bindingSource1, "CustomerCode");
txtCustomerName.DataBindings.Add("Text", bindingSource1, "CustomerName");
txtAddress.DataBindings.Add("Text", bindingSource1, "Address");
txtContact.DataBindings.Add("Text", bindingSource1, "Contact");
txtPhone.DataBindings.Add("Text", bindingSource1, "Phone");
txtEmail.DataBindings.Add("Text", bindingSource1, "Email");
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
private void button1_Click(object sender, EventArgs e)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
bindingSource1.AddNew();
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
private void button4_Click(object sender, EventArgs e)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
bindingSource1.EndEdit();