CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2001
    Posts
    71

    Question "Failed to enable constraints. One or more rows contain values violating non-null, un

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





    Hi!

    I get this error when I excetute this code

    (error on line: m_dataAdapter.Fill(m_dsCarTrade,"CustomerAddress")


    also I get one error in one Row:

    <error: an exception of type: {System.Data.StrongTypingException} occurred>

    (Tables have a relationship to eachother)


    Code:
    		private OleDbDataAdapter m_dataAdapter;
    
    		private OleDbConnection m_accessConnection;
    
    		private OleDbCommand m_accessCommand;
    
    
    		private	const string m_conStrAccessConnection  = "provider=Microsoft.JET.OLEDB.4.0; " + 
    													   "data source = C:\\Visual Studio Projects\\" +
    													   "CarTrade\\CarTradeDB.mdb";	
    
                    private const string m_conStrSelectCommandCustomer = "SELECT Customer.*, CustomerAddress.* FROM Customer INNER JOIN CustomerAddress ON Customer.CustomerID = CustomerAddress.CustomerID";
    
    
    		private void LoadFreshCustomersFromDB()
    		{
    			//we create an access object
    			m_accessConnection = new OleDbConnection(m_conStrAccessConnection);
    			m_accessCommand = new OleDbCommand(m_conStrSelectCommandCustomer, m_accessConnection);
    			m_dataAdapter = new OleDbDataAdapter(m_accessCommand);
    
    			//we open the connection to DB
    			m_accessConnection.Open();
    
    			try
    			{
    				m_dataAdapter.Fill(m_dsCarTrade,"CustomerAddress");
    
    				m_dataAdapter.Fill(m_dsCarTrade,"Customer");
    
    			}
    			catch (Exception e)
    			{
    				MessageBox.Show("Sorry....but we have some problems with database. " + "Error message from database : " + e.Message,"ERROR!!!");
    
    			}
    			finally
    			{
    				//we close the connection to DB
    				m_accessConnection.Close();
    			}
    
    			m_dtCustomers = m_dsCarTrade.Tables["Customer"];
    		}
    Know someone why this error caused?

  2. #2
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    looks like your query must be failing. check executing the query in Query Analyzer manually. and then give the corrected query in here.

    since when Fill also executes query and fails if it fails to execute the query.

    Paresh

  3. #3
    Join Date
    Oct 2001
    Posts
    71
    sorry but what is a Query Analyzer ?

    and where can I find that Query Analyzer?


    gicio

  4. #4
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    QueryAnalyzer comes with SQL SERVER. when u start Enterprise edition then u can see that. and u can check ur queries there before writing..

    Check Enterprise Manager that comes with SQL Server.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured