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 SinghPosted Jul 7, 2021, 1:52 PM
Ramco RamcoPosted Jul 7, 2021, 12:34 PM
Sachin SinghPosted Jul 7, 2021, 10:53 AM
Ramco RamcoPosted Jul 7, 2021, 10:38 AM
Sachin SinghPosted Jul 7, 2021, 10:26 AM
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.
Ramco RamcoPosted Jul 7, 2021, 9:45 AM
Sachin SinghPosted Jul 7, 2021, 9:04 AM
Sachin SinghPosted Jul 6, 2021, 9:18 AM
Ramco RamcoPosted Jul 6, 2021, 6:13 AM
Sachin SinghPosted Jul 5, 2021, 6:49 PM
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}
Salman BegPosted Jul 5, 2021, 6:14 PM