Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 POS_BUPO
- {
- public partial class frm_addproduct : Form
- {
- public frm_addproduct()
- {
- InitializeComponent();
- }
- Main viewmain = new Main();
- SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\SnowPrince\Desktop\POS_BUPO\POS_BUPO\Product.mdf;Integrated Security=True;Connect Timeout=30");
- private void btn_back1_Click(object sender, EventArgs e)
- {
- this.Close();
- viewmain.Show();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (txtAddCode.Text == "")
- {
- label5.Visible = true;
- }
- if(txtAddName.Text == "")
- {
- label6.Visible = true;
- }
- if(txtAddDes.Text == "")
- {
- label7.Visible = true;
- }
- if(txtAddPrice.Text == "")
- {
- label8.Visible = true;
- }
- else
- {
- conn.Open();
- SqlCommand cmd = new SqlCommand("INSERT INTO PData (ProductCode , ProductName , Description , Price) " +
- "VALUES (@ProductCode , @ProductName , @Description , @Price ) ", conn);
- cmd.Parameters.AddWithValue("@ProductCode ", txtAddCode.Text);
- cmd.Parameters.AddWithValue("@ProductName ", txtAddName.Text);
- cmd.Parameters.AddWithValue("@Description ", txtAddDes.Text);
- cmd.Parameters.AddWithValue("@Price ", txtAddPrice.Text);
- cmd.ExecuteNonQuery();
- conn.Close();
- MessageBox.Show("ทำการเก็บข้อมูลเสร็จสิ้น","Save Data",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
- txtAddCode.Clear();
- txtAddDes.Clear();
- txtAddName.Clear();
- txtAddPrice.Clear();
- conn.Close();
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- txtAddCode.Clear();
- txtAddDes.Clear();
- txtAddName.Clear();
- txtAddPrice.Clear();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement