Hi guys,
I am working on an ASP.NET Core Blazor Server app. I have one to many relationships between Order and OrderDetail entities. I couldn't find a way to insert data into tables from excel upload. Any help would be great.
Thanks in advance.
Here are the entities:
public class Order
{
public int Id { get; set; }
[Required]
public DateTime OrderDateTime { get; set; }
[Required]
[MaxLength(250)]
public string CustomerName { get; set; }
[Required]
[MaxLength(250)]
public string VendorName { get; set; }
public string Status { get; set; }
[MaxLength(50)]
public string DoneBy { get; set; }
public List OrderDetails { get; set; }
}
public class OrderDetail
{
public int Id { get; set; }
[Required]
[MaxLength(100)]
public string ProductCode { get; set; }
[Required]
[MaxLength(250)]
public string ProductName { get; set; }
[Required]
public int BuyQuantity { get; set; }
[Required]
public int SellQuantity { get; set; }
public double CostRatio { get; set; }
public double UnitCost { get; set; }
public double TotalBuyPrice { get; set; }
public double TotalSellPrice { get; set; }
[MaxLength(150)]
public string ShippingNumber { get; set; }
public string Status { get; set; }
[MaxLength(150)]
public string TrackingNumber { get; set; }
[MaxLength(400)]
public string Description { get; set; }
public int OrderId { get; set; }
public virtual Order Order { get; set; }
}
Here is the sample excel:

RaysefoPosted Jul 20, 2022, 6:00 PM
Jaydeep PatilPosted Jul 16, 2022, 6:01 AM
Check the following link that might help you to import EXCEL data into the SQL Tables through C# Code
https://www.c-sharpcorner.com/article/import-excel-data-into-sql-table-using-sqlbulkcopy-in-c-sharp/
https://www.c-sharpcorner.com/UploadFile/0c1bb2/inserting-excel-file-records-into-sql-server-database-using/
Regards,
Jaydeep Patil
Jignesh KumarPosted Jul 15, 2022, 3:38 AM