|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (6 bit)
Join Date: Oct 2002
Posts: 55
|
"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: (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"];
}
gicio |
|
|
|
|
|
#2 |
|
Member (12 bit)
Join Date: Mar 1999
Location: MN or WI
Posts: 3,017
|
This is Java?
Can you provide the information about OleDbDataAdapter.Fill()? |
|
|
|
|
|
#3 |
|
Professional gadfly
|
This is C++, right?
I found this as a possible solution: "1) "Failed to enable constraints" usually means there are constraints in your DataSet that your database tables don't satisfy. First, try removing all your DataSet constraints." I can't seem to find where you initialize m_dsCarTrade, so I am assuming you initialize it elsewhere. Try setting m_dsCarTrade.EnforceConstraints=False. |
|
|
|
|
|
#4 |
|
Member (6 bit)
Join Date: Oct 2002
Posts: 55
|
it's C#
gicio |
|
|
|
|
|
#5 |
|
Registered User
Join Date: Nov 2001
Posts: 1,965
|
I was really puzzled when reading your code, it uses const so it's not Java, but everything else (private location, exception handling ...) looks like Java!
Any way, I'm sorry I don't know C#, so I can help. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|