0

I am using DataAdapter("SDM_Tran_GenerateInvoice") inside DataSet("SDMDAL.xsd") in my project.

Below is the structure of DataAdapter along with the Stored Procedure names in it: enter image description here

Below is the Table structure Im using for the same: enter image description here

I am calling this DataAdapter inside Class file named as SDM.InvoiceBLL.cs:

using SDMDALTableAdapters;

public class SDM_Invoice
{
    private SDM_Tran_GenerateInvoiceTableAdapter _GenerateInvoiceTableAdapter = null;
    protected SDM_Tran_GenerateInvoiceTableAdapter Adapter
    {
        get
        {
            if (_GenerateInvoiceTableAdapter == null)
                _GenerateInvoiceTableAdapter = new SDM_Tran_GenerateInvoiceTableAdapter();

            return _GenerateInvoiceTableAdapter;
        }
    }

    #region GET
    public SDMDAL.SDM_Tran_GenerateInvoiceDataTable SelectInvoice(string _SPID)
    {
        return Adapter.SelectInvoice(_SPID);         }
    public SDMDAL.SDM_Tran_GenerateInvoiceDataTable GetInvoiceBillingBySPID(string _SPID)
    {
        return Adapter.GetInvoiceBillingBySPID(_SPID); //getting error for this Stored Procedure

    }
    public SDMDAL.SDM_Tran_GenerateInvoiceDataTable GetInvoiceID()
    {
        return Adapter.GetInvoiceID();
    }
    public SDMDAL.SDM_Tran_GenerateInvoiceDataTable GetInvoiceNumber()
    {
        return Adapter.GetInvoiceNumber();
    }
    #endregion
}

and then calling the SelectInvoice() function of class file inside Default.aspx.cs page, to display records in RadGrid:

protected void rgInvoice_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
        rgInvoice.DataSource = SDM.Invoice.GetInvoiceBillingBySPID(lblId.Text);
}

Below is the GetInvoiceBillingBySPID(_SPID) Stored Procedure

ALTER PROCEDURE [dbo].[SDM_Select_BillingBySPID_Invoice]
    @SPID as nvarchar(50)
    AS
BEGIN

    SET NOCOUNT ON; 
SELECT 
--B.ID,
B.BillingID, 
DCIDescription, --
(SELECT BUName FROM dbo.SDM_Master_BU WITH (NOLOCK) WHERE BUID=AfoBUID) as BUName, --
(SELECT BUfoStatusID FROM dbo.SDM_Master_BU WITH (NOLOCK) WHERE BUID=AfoBUID) as BUfoStatusID --
FROM SDM_Tran_Billing B WITH (NOLOCK),
dbo.SDM_Tran_DCI WITH (NOLOCK), 
dbo.SDM_Tran_Allocation WITH (NOLOCK)
WHERE B.BfoAllocationID=AllocationID and AfoDCIID=DCIID and DCIfoSPID=@SPID and B.BfoStatusID=1

END

but when I run Default.aspx page, everytime I get below error at line
return Adapter.GetInvoiceBillingBySPID(_SPID);

enter image description here

Below is the code of the location it is showing in the Error Snapshot - Source File:

enter image description here

Please note that I am very new in DataAdapter and Asp.Net (C#).
Please let me know what mistake I am doing in my code And what does this error mean ? Please reply in simple way so that I can understand.
Thanks in advance

timz_123
  • 435
  • 1
  • 9
  • 47
  • The datatable/dataset in your program contains constraints that weren't met by the data in the database. As an example, you might be trying to load two sets of tables into two DataTable objects in one DataSet, and the DataSet has specified foreign key relationship between the two, which either doesn't match the database, or perhaps there's no such relationship in the database. When you load the data, there's a row in one table containing a value that should point to an existing primary key in the other table, but there's no such key value in that other table. And then you get that exception. – Lasse V. Karlsen Jul 24 '15 at 08:12
  • @Lasse: Thankyou for the reply. I am getting this exception in `GetInvoiceBillingBySPID()` Stored Procedure. Using this SP I am binding the RadGrid only. Please let me know how to solve it. Please take a look to the SP I have attached in my posted question. I have specified all the code along with Database structure I am using for this. I am very new in DataAdapter and asp.net. Please help me to resolve it. – timz_123 Jul 24 '15 at 08:22
  • Have a look at this (possible duplicate) thread: http://stackoverflow.com/questions/7026566/failed-to-enable-constraints-one-or-more-rows-contain-values-violating-non-null – Volkan Paksoy Jul 24 '15 at 10:30

0 Answers0