티스토리 뷰



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DataSetSample
{
    public partial class Form1 : Form
    {
        private DataSet ourDataSet;
        private DataTable ourDataTable;
        private BindingSource ourBindingSource;

        public Form1()
        {
            InitializeComponent();
            InitializeMyComponent();
        }

        private void InitializeMyComponent()
        {
            ourDataSet = new DataSet("Memorizer");
            ourDataTable = new DataTable("Cards");
            ourDataSet.Tables.Add(ourDataTable);
           
            ourDataTable.Columns.Add("Page", typeof(string));
            ourDataTable.Columns["Page"].AllowDBNull = false;

            this.components = new System.ComponentModel.Container();
            ourBindingSource = new System.Windows.Forms.BindingSource(this.components);
            ourBindingSource.DataSource = ourDataSet;
            ourBindingSource.DataMember = "Cards";
           
            this.dataGridView1.DataSource = ourBindingSource;
            this.bindingNavigator1.BindingSource = ourBindingSource;
        }

        private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
            MessageBox.Show(e.Exception.Message);
        }

        private void buttonNew_Click(object sender, EventArgs e)
        {
            try
            {
                ourBindingSource.AddNew();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}





공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함