|  |  | 
          
            | Code (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;
using System.Data.OleDb;
namespace HotelCheck
{
    public partial class ข้อมูลลูกค้า : Form
    {
        Database db = new Database();
        Check_Num num = new Check_Num();
        public ข้อมูลลูกค้า()
        {
            InitializeComponent();
        }
        private void ข้อมูลลูกค้า_Load(object sender, EventArgs e)
        {
              cus_ID.Text = db.auto_id("tb_Cus", "cus_ID").ToString();
              string sql = "SELECT * FROM tb_Cus ORDER BY cus_ID DESC";
              OleDbCommand com = new OleDbCommand(sql, db.conn);
              OleDbDataReader dr = com.ExecuteReader();
         
            int i = 0;
            while(dr.Read()){
                dataGridView1.Rows.Add();
                dataGridView1.Rows[i].Cells[0].Value = dr["cus_ID"];
                dataGridView1.Rows[i].Cells[1].Value = dr["cus_FName"];
                dataGridView1.Rows[i].Cells[2].Value = dr["cus_LNAME"];
                dataGridView1.Rows[i].Cells[3].Value = dr["cus_Phone"];
                dataGridView1.Rows[i].Cells[4].Value = dr["cus_Address"];
                i++;
                
            }
            dr.Close();
            db.conn.Close();
            
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if(cus_FName.Text == ""){
                MessageBox.Show("กรุณากรอกชื่อ");
                cus_FName.Focus();
            }else if(cus_LName.Text == ""){
                MessageBox.Show("กรุญากรอกนามสกุล");
                cus_LName.Focus();
            }
            else if (cus_Phone.Text == "")
            {
                MessageBox.Show("กรุณากรอกหมายเลขโทรศัพท์");
                
            }     
            else if (num.is_numeric(cus_Phone.Text) == false)
            {
                MessageBox.Show("กรุณากรอกเป็นตัวเลขเท่านั้น");
                
            }
            else if (cus_Phone.TextLength != 10)
            {
                MessageBox.Show("กรุณากรอกเบอร์โทรศัพท์ให้ครบ 10 หลัก");
            }
            else if (cus_Address.Text == "")
            {
                MessageBox.Show("กรุณากรอกที่อยู่");
            }
            else
            {
                string sql = "INSERT INTO tb_Cus VALUES";
                sql += "('" + cus_ID.Text + "',";
                sql += "'" + cus_FName.Text + "',";
                sql += "'" + cus_LName.Text + "',";
                sql += "'" + cus_Phone.Text + "',";
                sql += "'" + cus_Address.Text + "')";
                try
                {
                    db.saveData(sql);
                    MessageBox.Show("บันทึกข้อมูลลูกค้าเสร็จเรียบร้อย");
                    clearData();
                }catch(Exception ex){
                }
            } 
        }
        void clearData()
        {
            cus_ID.Text = db.auto_id("tb_Cus","cus_ID").ToString();
            cus_FName.Clear();
            cus_LName.Clear();
            cus_Phone.Clear();
            cus_Address.Clear();
        }
   }
}
 พอผมกดบันทึกความข้อมูลขึ้นแบบนี้คับ
 
 Code
 
 ExcuteNonQuert requires an open and available connection. The connection's current state is closed.
 
 
 
 Tag : .NET, Ms Access, C#
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2015-03-25 00:27:38 | By :
                          dsefx | View :
                          939 | Reply :
                          3 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |