2015年12月17日 星期四


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;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            textBox1.DataBindings.Add("Text", bindingSource1, "name", true);
            textBox2.DataBindings.Add("Text", bindingSource1, "sex", true);
            textBox3.DataBindings.Add("Text", bindingSource1, "tel", true);
            textBox4.DataBindings.Add("Text", bindingSource1, "stu_no", true);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 這行程式碼會將資料載入 'db1DataSet.DataTable1' 資料表。您可以視需要進行移動或移除。
            this.dataTable1TableAdapter.Fill(this.db1DataSet.DataTable1);
            // TODO: 這行程式碼會將資料載入 'db1DataSet.record' 資料表。您可以視需要進行移動或移除。
            this.recordTableAdapter.Fill(this.db1DataSet.record);
            // TODO: 這行程式碼會將資料載入 'db1DataSet.person' 資料表。您可以視需要進行移動或移除。
            this.personTableAdapter.Fill(this.db1DataSet.person);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            bindingSource1.MoveFirst();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bindingSource1.MoveNext();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            bindingSource1.MovePrevious();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

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

        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                bindingSource1.EndEdit();
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }

}





tabcontrol - tabpage
binding Source
datagridview
bindingNavigator - biding source

textbox
label

2015年12月11日 星期五

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;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int[] array = new int[4];
        int mysum = 0;
        public Form1()
        {
            InitializeComponent();
            textBox1.DataBindings.Add("Text", bindingSource3, "name", true);
            textBox2.DataBindings.Add("Text", bindingSource3, "math", true);
            array[0] = 0;
            array[1] = 0;
            array[2] = 0;
            array[3] = 0;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 這行程式碼會將資料載入 'db1DataSet.DataTable1' 資料表。您可以視需要進行移動或移除。
            this.dataTable1TableAdapter.Fill(this.db1DataSet.DataTable1);
            // TODO: 這行程式碼會將資料載入 'db1DataSet.record' 資料表。您可以視需要進行移動或移除。
            this.recordTableAdapter.Fill(this.db1DataSet.record);
            // TODO: 這行程式碼會將資料載入 'db1DataSet.person' 資料表。您可以視需要進行移動或移除。
            this.personTableAdapter.Fill(this.db1DataSet.person);

        }

        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void bindingNavigatorMoveNextItem2_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            bindingSource3.MoveFirst();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bindingSource3.MoveNext();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            array[0] = int.Parse(textBox2.Text);
            for (int i = 0; i < 3; i++)
            {
                array[i] = int.Parse(textBox2.Text);
                bindingSource3.MoveNext();
            }
            for (int i = 0; i < 3; i++)
            {
                array[i] = mysum + array[i];
            }
            textBox3.Text = mysum.ToString();
        }
    }
}


tabcontrol - tabpage
binding Source
datagridview
bindingNavigator - biding source

textbox
label


2015年12月3日 星期四

C# 資料庫




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;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 這行程式碼會將資料載入 'db1DataSet1.DataTable2' 資料表。您可以視需要進行移動或移除。
            this.dataTable2TableAdapter.Fill(this.db1DataSet1.DataTable2);
            // TODO: 這行程式碼會將資料載入 'db1DataSet.DataTable1' 資料表。您可以視需要進行移動或移除。
            this.dataTable1TableAdapter.Fill(this.db1DataSet.DataTable1);
            // TODO: 這行程式碼會將資料載入 'db1DataSet.record' 資料表。您可以視需要進行移動或移除。
            this.recordTableAdapter.Fill(this.db1DataSet.record);
            // TODO: 這行程式碼會將資料載入 'db1DataSet.person' 資料表。您可以視需要進行移動或移除。
            this.personTableAdapter.Fill(this.db1DataSet.person);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            // If you are not at the end of the list, move to the next item
            // in the BindingSource.
            if (bindingSource1.Position + 1 < bindingSource1.Count)
                bindingSource1.MoveNext();

            // Otherwise, move back to the first item.
            else
                bindingSource1.MoveFirst();


        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            // Force the form to repaint.
            //this.Invalidate();
            //textBox1.DataBindings.Add("Text", bindingSource1, "name");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // If you are not at the end of the list, move to the next item
            // in the BindingSource.
            if (bindingSource1.Position - 1 > bindingSource1.Count)
                bindingSource1.MoveNext();

            // Otherwise, move back to the first item.
            else
                bindingSource1.MoveFirst();


        }

        private void button3_Click(object sender, EventArgs e)
        {
            // Force the form to repaint.
            this.Invalidate();
            textBox1.DataBindings.Add("Text", bindingSource1, "name");
        }


    }
}


binding Source - dataset
tabcontrol
datagridview
bindingNavigator
textbox