|  |  | 
          
            | มันไม่ผ่านอะครับ ลองดูรูปก่อนนะครับ 
 
  
 โค๊ตที่ใช้ครับ
 
 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.SqlClient;
 
 
 namespace Insert01
 {
 public partial class Insert02 : Form
 {
 SqlConnection conn;
 SqlCommand comm;
 SqlDataReader Dr;
 string Pcode,Pname,Bname,Cname,Aname;
 int Price,Psize;
 public Insert02()
 {
 InitializeComponent();
 conn = new SqlConnection("data source=.\\krittin;initial catalog=ConsumerProducts;integrated security=True;");
 }
 
 private void button1_Click(object sender, EventArgs e)
 {
 try
 {
 Pcode = textBox1.Text;
 Pname = textBox2.Text;
 Bname = textBox3.Text;
 Psize = Convert.ToInt32(textBox4.Text);
 if (radioButton1.Checked == true)
 {
 Cname = "อุปโภค";
 }
 if (radioButton2.Checked == true)
 {
 Cname = "บริโภค";
 }
 Price = Convert.ToInt32(textBox6.Text);
 comm = new SqlCommand("select * from Consumer where ProductConsumer='" + Pcode + "'", conn);
 conn.Open();
 Dr = comm.ExecuteReader();
 if (Dr.Read())
 {
 MessageBox.Show("รหัสนี้มีอยู่แล้ว กรุณาป้อนใหม่อีกครั้ง");
 conn.Close();
 }
 else
 {
 conn.Close();
 comm = new SqlCommand("INSERT into Consumer ('"+Pcode+"' , '"+Pname+"' , '"+Bname+"' , "+Psize+" , '"+Cname+"' , "+Price+")", conn);
 
 if (MessageBox.Show("บันทึกใช่หรือไม่", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
 {
 conn.Open();
 comm.ExecuteNonQuery();
 conn.Close();
 MessageBox.Show("บันทึกสำเร็จ");
 textBox1.Text = "";
 textBox2.Text = "";
 textBox3.Text = "";
 textBox4.Text = "";
 textBox6.Text = "";
 }
 else
 {
 this.Close();
 }
 }
 }
 catch (Exception err)
 {
 MessageBox.Show(err.ToString());
 }
 }
 }
 }
 
 
 
 Tag : Ms SQL Server 2012, VS 2012 (.NET 4.x)
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2019-02-26 23:44:14 | By :
                          2281015975292519 | View :
                          877 | Reply :
                          2 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |