Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4034604
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:59:35+00:00 2026-05-20T11:59:35+00:00

I am creating a C# Windows application which is based on a medical inventory.In

  • 0

I am creating a C# Windows application which is based on a medical inventory.In this application I have mainly three forms as PurchaseDetail,SalesDetail,and StockDetail.

Now I want a functionality in which if I insert or modify the records in PurchaseDetail,or SalesDetail, the data in the StockDetail should also be modified.(for example if i insert some quantity of medicines in PurchaseDetail then Quantity of that medicine in StockDetail should also modified and same as for SalesDetail )

Columns in PurchaseDetail: Id(Primary Key and auto increment int),BatchNumber,ProductName,ManufacturingDate,ExpiryDate,Rate,MRP,Tax,Discount,Quantity

Columns in SalesDetail: Id(PrimaryKey and auto increment int),BillNumber,CustomerName,BatchNumber,Quantity,Rate,SalesDate

Columns in StockDetail: Id(Primary Key and auto increment int),ProductId,ProductName,OpeningStock,ClosingStock,PurchaseQty,DispenseQty,PurchaseReturn,DispenseReturn

Please help me with any suitable example or code

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:59:36+00:00Added an answer on May 20, 2026 at 11:59 am

    you could easily write multiple SQL statements separated by semicolon “;”

    example:

    INSERT INTO PurchaseDetail (BatchNumber, ProductID, Quantity) VALUES (@BatchNumber, @ProductID, @Quantity);
    INSERT INTO StockDetail (ProductID, ProductName, OpeningStock, ClosingStock, PurchaseQty, DispenseQty, PurchaseReturn,DispenseReturn) SELECT ProductID, ProductName, ClosingStock, ClosingStock + @Quantity, @Quantity, 0, 0, 0 FROM StockDetail WHERE ProductID = @ProductID AND ID = (SELECT TOP 1 ID FROM StockDetail WHERE ProductID = @ProductID ORDER BY ID)
    

    And you really should not be storing the product name all over again in each of the table. Instead, you should be storing ProductID. Your SalesDetails doesn’t say which product is sold.

    The following is a suggested schema that is more normalized:

    Product (ID, ProductName, Stock)
    PurchaseDetail (ID, BatchID, ProductID, Quantity, …)
    SalesDetail (ID, BillID, ProductID, Quantity, …)
    PurchaseBatch (ID, PurchaseDate)
    SalesBill (ID, SalesDate, CustomerID)

    If you ever need to know the opening, closing, purchase and dispense for a specific duration, you can always run the SQL:

    Current stock:

    SELECT Stock FROM Product WHERE ID = @ProductID
    

    Purchased from @StartDate to @EndDate:

    SELECT SUM(Quantity) FROM PurchaseDetail INNER JOIN PurchaseBatch ON PurchaseDetail.BatchID = PurchaseBatch.ID WHERE PurchaseBatch.PurchaseDate >= @StartDate AND PurchaseBatch.PurchaseDate < @EndDate AND PurchaseDetail.ProductID = @ProductID
    

    Sold from @StartDate to @EndDate:

    SELECT SUM(Quantity) FROM SalesDetail INNER JOIN SalesBill ON SalesDetail.BillID = SalesBill.ID WHERE SalesBill.SalesDate >= @StartDate AND SalesBill.SalesDate < @EndDate AND SalesDetail.ProductID = @ProductID
    

    Purchased from @EndDate till now:

    SELECT SUM(Quantity) FROM PurchaseDetail INNER JOIN PurchaseBatch ON PurchaseDetail.BatchID = PurchaseBatch.ID WHERE PurchaseBatch.PurchaseDate >= @EndDate AND PurchaseDetail.ProductID = @ProductID
    

    Sold from @EndDate till now:

    SELECT SUM(Quantity) FROM SalesDetail INNER JOIN SalesBill ON SalesDetail.BillID = SalesBill.ID WHERE SalesBill.SalesDate > @EndDate AND SalesDetail.ProductID = @ProductID
    

    Therefore,

    opening from @StartDate till @EndDate =
    Current stock
    – Purchased from @StartDate to @EndDate
    – Purchased from @EndDate till now
    + Sales from @StartDate to @EndDate
    + Sales from @EndDate till now

    closing from @StartDate till @EndDate =
    Current stock
    – Purchased from @EndDate till now
    + Sales from @EndDate till now

    And you also have
    Sales from @StartDate to @EndDate
    Purchased from @StartDate to @EndDate

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok So I'm creating a Windows Forms Application for some guy using C# and
I have created a windows form application which uses an SQL database. The database
I have created one Windows Forms application with C# and MySQL (using MySQL Connector
I am creating a C# windows application to create an Excel 2003 sheet. There
We are creating a Windows Form application (C# or VB.NET) that needs to reference
I am creating a C# Windows Mobile application that I need to programmatically invoke
I am creating a windows service and want to know best practices for this.
I am creating a Windows Forms control derived from UserControl to be embedded in
We have a mature Windows desktop application written in C++. The application's GUI sits
We're building an application designed to run on Windows-based servers. One of the considerations

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.