I am not in a position to test it right now, and my experience with
DotNet
is with MS SQL Server, rather than with Jet, but I would have tried
(sorry,
it is in C# ) something like :
// references
using System;
using System.Data;
using System.Data.SqlClient; // to be changed if you use Jet
// ... in your code ...
String connectionString = "Provider=... " // ADO.Net connection
string
// probably something like
"Provider=Microsoft.Jet.OLEDB.4.0;
....
// in your case
using ( SqlConnection xnn = new SqlConnection(connectionString) )
{
System.Diagnostics.Debug.Assert(
null != xnn,
"Invalid connection string ? ");
xnn.Open() ;
System.Diagnostics.Debug.Assert(
xnn.State == ConnectionState.Open,
"Cannot open the db ? busy? poor connectivity ? ");
using ( SqlCommand cmd = xnn.CreateCommand() )
{
cmd.CommandType= CommandType.Text ;
cmd.CommandString = "ALTER TABLE ... " ;
cmd.ExecuteNonQuery() ;
}
}
Note: You have to change the data type for xnn, and cmd, here, they are
specific for MS SQL Server.
Vanderghast, Access MVP
Shnizles said:
im not using vba to excute the queries ,
im using vb.net ,
and well i tried to connect with OLEDB and ADODB connectors
both resulted with the same errors ,
as well when i run the sql query in access 2007 sql design tab ,
same error.
thanks for the response any other ideas?
:
Have you tried using ADO?
CurrentProject.Connection.Execute "ALTER TABLE Holiday ADD CONSTRAINT
CalendarHoliday FOREIGN KEY (calendarid) REFERENCES Calendar (id) ON
DELETE
CASCADE"
in the immediate (debug) window...
Once added, the constraint will work as well in DAO than in ADO, but
it
is
just that many Jet 4.0 extensions work only under ADO, like here,
adding
a
cascading referential integrity.
Vanderghast, Access MVP
hi everyone ,
i am trying to add a constraint to a table ,
as the ms access guides suggested i have crafted the following
query:
ALTER TABLE Holiday ADD CONSTRAINT CalendarHoliday FOREIGN KEY
([calendarid]) REFERENCES Calendar ([id]) ON DELETE CASCADE
the above query result in a syntax error ,
the problem seems to be "ON DELETE CASCADE" , when i remove it the
relationship is being added just fine , however the constraint must
have
Delete cascade enabled ,
can anyone point me to the problem ,how can i solve it ,
thank you for your help!