Hi
I have below object. How to pass values from database to object. There can be more than 1 items
public class DocDtls
{
public string Typ { get; set; }
public string No { get; set; }
public string Dt { get; set; }
}
public class ItemList
{
public int ItemNo { get; set; }
public string SlNo { get; set; }
public string IsServc { get; set; }
public string PrdDesc { get; set; }
public string HsnCd { get; set; }
public int Qty { get; set; }
public int FreeQty { get; set; }
public string Unit { get; set; }
public int UnitPrice { get; set; }
public int TotAmt { get; set; }
public int Discount { get; set; }
public int PreTaxVal { get; set; }
public int AssAmt { get; set; }
public int GstRt { get; set; }
public int IgstAmt { get; set; }
public int CgstAmt { get; set; }
public int SgstAmt { get; set; }
public int OthChrg { get; set; }
public int TotItemVal { get; set; }
}
public class Root
{
public DocDtls DocDtls { get; set; }
public List ItemList { get; set; }
}
Thanks
Gowtham CpPosted Aug 19, 2024, 10:42 AM
To pass values from a database to your objects in C#, you need to establish a database connection, execute SQL queries to fetch data, and then map the retrieved data to your object's properties.
Here's the key part of the code:
Ajay BansodePosted Aug 19, 2024, 8:33 AM
using ADO.NET, we can pass values from database to object,
there are multiple ways to fetch that data,
1st way :- >
first, we can create a select statement to get all data in the Database,
there are 2 separate select queries for both document details and item lists. create and procedure for it.
second on the API side or Framework side execute that procedure and get data in the data table.
there are 2 rows in the data table due to 2 select queries, filling data in the respective contract.
2nd way :->
if we are ready to send multiple requests to the database then send 2 different requests to the database and fetch data one after another that is a simple way to get data and fill it according to it in the root contract.
this is the solution as per my knowledge,