Click here to Skip to main content
15,118,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi this is my Stored Procedure on SQL Server 2008

SQL
ALTER PROCEDURE getEmailThemes
AS
BEGIN
	SELECT EpaperTheme.ID AS ThemeID, EpaperTheme.Title AS Title, EpaperTheme.CreationDate, MarketingCategory.Title AS Category
	FROM EpaperTheme JOIN MarketingCategory ON EpaperTheme.Category_ID = MarketingCategory.ID
END
GO


and this is my code behind
C#
string ConnectionString = "Data Source=.;Initial Catalog=myDatabase;Integrated Security=SSPI";
            SqlConnection Connection = new SqlConnection(ConnectionString);
            string command = "SELECT * FROM MarketingCategory";
            SqlCommand Command = new SqlCommand(command, Connection);
            DataTable dt = new DataTable(); ;
            Connection.Open();
            SqlDataReader dr = Command.ExecuteReader();
            dt.Load(dr);
            NumberOfCategory = dt.Rows.Count - 1;
            //string[][] EmailArchives = new string[NumberOfCategory][];
            string[] Tbody = new string[NumberOfCategory];
            drpCategoryList.DataSource = dt;
            drpCategoryList.DataValueField = "Title";
            drpCategoryList.DataTextField = "Title";
            drpCategoryList.DataBind();

            dt.Clear();
            command = "getEmailThemes";
            Command.CommandText = command;
            SqlDataReader dre = Command.ExecuteReader();
            dt.Load(dre); //error

          

           Connection.Close();


but when i execute the code, gets this error:

HTML
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.


how can i solve this problem??
Posted
Comments
Sandeep Mewara 7-Feb-13 11:41am
   
I don't see any link of code-behind with stored procedure. Confused.
Mike Meinz 7-Feb-13 12:20pm
   
1. Use the Visual Studio Debugger and step through your code to determine which line throws the exception. Then determine the values of the pertinent variables at that time.

2. Try running your SQL in a query window within SQL Server Management Studio to help you pinpoint the error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900