zoukankan      html  css  js  c++  java
  • 使用BindingSource绑定数据库

    1.前言

    在 C# 中我们常见的绑定数据库的方式是通过 ADO.NET 来实现的,除此之外,还可以直接在 form 的设计界面实现对数据源的绑定,这就是使用 BindingSource 实现的方法,下面将介绍这种方法。

    2.绑定数据源

    在 form 设计界面,点击 DataGridView 右上角的箭头,出现以下界面:

    在 Choose Data Source 对应的下拉框中选择或者创建数据源,

    绑定数据源后的结果如下:

    此时 DataGridView 会自动完成 Column 的创建,项目将会自动为其创建相关的控件,如下图所示:

    对应的在 Form 的中将显示以下代码:

    private void Form1_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'testDataSet.DebtorData' table. You can move, or remove it, as needed.
        this.debtorDataTableAdapter.Fill(this.testDataSet.DebtorData);
    }

    此时,就完成了通过 BindingSource 实现了数据源的绑定。

    3.实现增删改查

    暂时没找到。

    4.TableAdapter Update

    private void Form1_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'testDataSet.T1' table. You can move, or remove it, as needed.
        this.t1TableAdapter.Fill(this.testDataSet.T1);
    }
    
    private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
        t1TableAdapter.Update(testDataSet.T1);
        testDataSet.T1.AcceptChanges();
    }
  • 相关阅读:
    在命令行下运行Matlab
    VMWare无法共享文件夹(Win7宿主机Ubuntu14.04客户机)
    [转] CVonline: Image Databases
    第二天
    第一天
    二宝软件的NABCD分析
    用c++实现环形数组的最大子数组之和
    返回一个二维整数数组中最大子数组的和
    求最大子数组之和
    四则运算
  • 原文地址:https://www.cnblogs.com/jizhiqiliao/p/9849314.html
Copyright © 2011-2022 走看看