none
insert in Datagridview RRS feed

All replies

  • Hello,

    Could you please provide us with more detailed information about your scenario? 

    Have a nice day!

    Best Regards,
    Lingzhi Sun


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, January 7, 2010 10:14 AM
    Moderator
  • I know It can use databinding but i dont know how to binding with join 3 table
    Thursday, January 7, 2010 11:24 AM
  • Hello,

    Sorry, but I still cannot catch your point.  Would you mind providing us with more detailed data structure, how do you want to insert the data and how do you need to make the JOIN query?  

    Best Regards,
    Lingzhi Sun


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, January 7, 2010 12:20 PM
    Moderator
  • product.cs
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.Linq;
    using System.Data.Linq.Mapping;

    namespace store.Product
    {
        public partial class product : Form
        {
            public product()
            {
                InitializeComponent();
            }

            private void label1_Click(object sender, EventArgs e)
            {

            }

            private void toolStripLabel4_Click(object sender, EventArgs e)
            {
                Product.search se = new store.Product.search();
                se.Show();
            }

            private void toolStripLabel6_Click(object sender, EventArgs e)
            {
                Product.unit unit = new store.Product.unit();
                unit.Show();

            }

            private void toolStripLabel7_Click(object sender, EventArgs e)
            {
                Product.productPromotion proPromo = new store.Product.productPromotion();
                proPromo.Show();
            }

            private void toolStripLabel8_Click(object sender, EventArgs e)
            {
                Product.productDetail prodetail = new store.Product.productDetail();
                prodetail.Show();
            }

            private void toolStripLabel11_Click(object sender, EventArgs e)
            {
                Product.createUnit unit = new store.Product.createUnit();
                unit.Show();
            }

            private void product_Load(object sender, EventArgs e)
            {
     
     
               Persistence.ProductPer pdp = new Persistence.ProductPer();
               DataContext db = pdp.connect();
               var list= pdp.showProduct(db);
             
              
              
               dgvProduct.DataSource = list;
               dgvProduct.Columns[0].HeaderText = "รหัสสินค้า";
               dgvProduct.Columns[1].HeaderText = "Barcode";
               dgvProduct.Columns[2].HeaderText = "ชื่อสินค้า";
               dgvProduct.Columns[3].HeaderText = "หน่วย";
               dgvProduct.Columns[4].HeaderText = "ราคาขาย";
               dgvProduct.Columns[5].HeaderText = "ราคาขายต่ำสุด";
     
            }

     
        }
    }


    productPer.cs

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Data.Linq;
    using System.Data.Linq.Mapping;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using store.Persistence;
    using System.Linq;
    using System.Collections;

    namespace store.Persistence
    {
        public class ProductPer
        {
            DataContext db;
            Table<ProductT>  ProductTable;
            Table<Unit> UnitTable;
            Table<ProductPrice> ProductPriceTable;
            public class ProductClass
            {
                public  int  Prod_id { get; set; }
                public string  Prod_barcode { get; set; }
                public string Prod_name { get; set; }
                public string Unit_name { get; set; }
                public  int  Price_min{ get; set; }
                public  int Prod_price { get; set; }
              

     
            }
            public DataContext connect()
            {
                Persistence.Connect conn = new Persistence.Connect();
                db = conn.connectDB();
                return db;

            }

            public List<ProductClass> showProduct(DataContext db)
            {
                ProductTable = db.GetTable<ProductT>();
                UnitTable = db.GetTable<Unit>();
                ProductPriceTable = db.GetTable<ProductPrice>();
                List<ProductClass> res = (from c1 in ProductTable
                          join c2 in UnitTable on c1.Unit_id equals c2.Unit_id
                          join c3 in ProductPriceTable on c1.Prod_price_id equals c3.Prod_price_id
                          select new ProductClass { Prod_id = c1.Prod_id, Prod_barcode = c1.Prod_barcode, Prod_name = c1.Prod_name, Unit_name = c2.Unit_name, Price_min = Convert.ToInt32(c1.Price_min), Prod_price = Convert.ToInt32(c3.Prod_price) }).ToList();
                return res;
            }
           
        }
    }

    I want to insert update and delete in dgvProduct.
    Friday, January 8, 2010 4:49 AM