Hi
I have below 2 classes & want to insert record using Ado.Net
public class Invoice
{
public Invoice()
{
}
[Key]
public string No { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public string DocDate { get; set; }
public virtual ICollection InvoiceDetails { get; set; }
public string Status { get; set; }
}
public partial class InvoiceDetail
{
public string DocNo { get; set; }
public Product Id { get; set; }
public decimal Quantity { get; set; }
public Nullable price { get; set; }
public Nullable GrossAmount { get; set; }
public Nullable NetAmount { get; set; }
}
Trying like below but it is not showing Invoice Details fields.
public int Add(Invoice objInvoice)
{
int i;
using (SqlConnection con = new SqlConnection(cs))
{
con.Open();
SqlCommand cmd = new SqlCommand("sp_Invoice", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@No", objInvoice.No);
cmd.Parameters.AddWithValue("@No", objInvoice.DocDate);
cmd.Parameters.AddWithValue("@No", objInvoice.Po_No);
cmd.Parameters.AddWithValue("@No", objInvoice.PO_Date);
cmd.Parameters.AddWithValue("@Action", "C");
i = cmd.ExecuteNonQuery();
}
return i;
}
Thanks

Sachin SinghRank #66 · 26.2K reputationPosted Jul 7, 2021, 9:52 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jul 7, 2021, 6:26 AM EDT
you need a relationship among your 3 tables, consider the Invoices as your InvoiceHeader, invoice_lines as your invoice_line, and product as your item table, your columns are correct but you need to relate them as shown below.
Salman BegRank #284 · 8.8K reputationPosted Jul 5, 2021, 2:14 PM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jul 5, 2021, 2:49 PM EDT
Your invoiceDetails is a collection inside invoice type, so you can access the invoiceDetails from the objInvoice.InvoiceDetails using foreach as foreach(var item in objInvoice.InvoiceDetail) {item.price}
Ramco RamcoRank #462 · 5.4K reputationPosted Jul 7, 2021, 5:45 AM EDT
Ramco RamcoRank #462 · 5.4K reputationPosted Jul 6, 2021, 2:13 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jul 6, 2021, 5:18 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jul 7, 2021, 5:04 AM EDT
Ramco RamcoRank #462 · 5.4K reputationPosted Jul 7, 2021, 6:38 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jul 7, 2021, 6:53 AM EDT
Ramco RamcoRank #462 · 5.4K reputationPosted Jul 7, 2021, 8:34 AM EDT