Resolved inserting data


Dec 22, 2022
Programming Experience
hi so im trying to learn linq

what i wan to do is
when u add row it will add automatically second row with different data

something like that


the second row added manually
what im trying to do is when the first one added to database will add the second one
so should be like that
insert into Product_Units values(    9, 7     ,6,      30           ,     180           )
---------------------------------   id, pid  ,  qty,     oneunitprice  ,totalprice

insert into Product_Units values(9,   7,    1,             180              ,180)
-------------------------------  id,  pid,  1,   totalprice.editvalue,totalprice.editvalue

void getdata()
    gridControl2.DataSource = priceunit.Products_Units.Where(x => x.Pro_ID == product.Pro_ID);


void save()

var Data2 = gridView2.DataSource as BindingList<DAL.Products_Unit>;
            foreach(var items in Data2)
                items.Pro_ID = product.Pro_ID;
                items.TotalSellPrice = Convert.ToDecimal(Txt_SalePRiceTax.Text);

Can you explain to us how this is related to LINQ?
It sounds like you don't really know what LINQ is. LINQ is Language INtegrated Query. It's a way to query data sources of various types directly in C# code. Inserting records into a database has nothing really to do with LINQ because there's no query. Maybe you are using LINQ to SQL but that's a specific data access technology and is not LINQ, any more than a golf ball is golf. If you're using the LINQ to SQL provider then that's important information but inserting data using LINQ to SQL doesn't actually involve LINQ. Maybe you're not even using LINQ to SQL. It's not really clear from the information you have provided.

If you're using SQL Server or another proper database then you could use a trigger to insert a second row, or else you might provide that functionality in your service layer. It's not really clear what would be the best option because you haven't really explained the situation fully. Whatever you do, it's unlikely to actually involve any LINQ.
hi sorry for my englihs .
im using LINQ to SQL
sorry if this not where i should post

i think i will just add a row and change the AllowEdit to false
something like that until i learn more about it and see

            var data2 = gridView2.DataSource as BindingList<DAL.Products_Unit>;
            data2.Add(new DAL.Products_Unit() { Unit_ID = db.Products_Units.First().Unit_ID , Unit_Qty=1,UnitSellPrice= Convert.ToDecimal(Txt_SalePRiceTax.EditValue )});

thanks and sorry for my english again
But are you really using LINQ to SQL? It's been "dead" for nearly 15 years

If you truly are using it, I recommend upgrading to Entity Framework so your learning is relevant to modern times. When a data access technology is almost older than some of the people who will answer your c# questions it's well past time to stop using it..
Top Bottom