Thread View: borland.public.delphi.aspdotnet.components.using
1 messages
1 total messages
Started by Vagelis
Wed, 14 Dec 2005 14:15
MsAccess db & bdpDataAdapters
Author: Vagelis
Date: Wed, 14 Dec 2005 14:15
Date: Wed, 14 Dec 2005 14:15
109 lines
4890 bytes
4890 bytes
Hi.
I use an MsAccess db and I try to use bdp components to establish a full
read-write connection with a master detail relation. The tables are
unrelated in the database. I make my own delphi relation between the 2
tables with key='ID' for the master Table and foreignKey='SID' for the
detail. I'm trying to give my own key and foreign key values each time I
insert new records. The idea is to to add a new detail record with proper
key and foreign key values whenever I insert a new record for the master
table. Performing the following code in the dbwebnavigator's click event of
the master table, the desired records are added in my database, BUT
1) if a post back of the page is caused in any way, I get a "Foreign key
values cannot be null" error.
2)if I close the application and reenter, everything works fine and my new
records are right there with proper key & foreign key values.
Since the AutoRefresh property of my dbwebDataSource is set to true and the
records have been inserted indeed, what's the problem? Why don't I get the
error right after I update the db?
//Code
Start-----------------------------------------------------------------------
----------------------------------------------------------------------
if e.ButtonName='Insert' then
begin
bdpConnection1.Open;
command := BdpCommand.Create;
command.Connection := bdpConnection1;
// build our own SQL Update statement
command.CommandText := 'SELECT MAX(ID) FROM Swmata_Description';
command.Prepare;
try
myDataReader :=
command.ExecuteReader(CommandBehavior.CloseConnection);
if myDataReader.Read then
dmaxID := myDataReader.GetInt32(0);
myDataReader.Close;
except
on E: Exception do
Response.Write(E.Message)
end;
command.Close;
command.Dispose;
bdpConnection1.Close;
obj := TObject(LongInt(Session.Item['maxID'])+1);
if DataTable0.Rows[DataTable0.Rows.Count-1].Item['ID'].Equals( obj )
then
exit;
r := DataTable0.NewRow;
r.Item['ID']:= TObject(LongInt(Session.Item['maxID'])+1);
r.Item['Antiproswpos']:= Session.Item['SupplierName'];
DataTable0.Rows.Add(r);
r1 := DataTable1.NewRow;
r1.Item['ID']:= TObject(DMaxId+1);
r1.Item['SID']:= TObject(LongInt(Session.Item['maxID'])+1);
r1.Item['Aa']:=TObject(1);
DataTable1.Rows.Add(r1);
try
DataSet1.EnforceConstraints := false;
bdpConnection1.Open;
trans := bdpConnection1.BeginTransaction;
bdpInsertCommand1.Transaction := trans;
bdpInsertCommand2.Transaction := trans;
bdpInsertCommand1.Prepare;
bdpInsertCommand2.Prepare;
bdpdataadapter1.Update(Dataset1);
bdpdataadapter2.Update(Dataset1);
bdpInsertCommand1.Close;
bdpInsertCommand2.Close;
try
trans.commit;
except
trans.Rollback;
end;
trans.Dispose;
bdpConnection1.Close;
DataSet1.AcceptChanges;
DataSet1.EnforceConstraints := true;
except
on E: Exception do
Response.Write(E.Message)
end;
if Dataset1.Tables[0].Rows[Dataset1.Tables[0].Rows.Count-1].HasErrors
then
Response.Write(Dataset1.Tables[0].Rows[Dataset1.Tables[0].Rows.Count-1].rowe
rror)
else
Dataset1.Tables[0].Rows[Dataset1.Tables[0].Rows.Count-1].AcceptChanges;
if Dataset1.Tables[1].Rows[Dataset1.Tables[1].Rows.Count-1].HasErrors
then
Response.Write(Dataset1.Tables[1].Rows[Dataset1.Tables[1].Rows.Count-1].rowe
rror)
else
Dataset1.Tables[1].Rows[Dataset1.Tables[1].Rows.Count-1].AcceptChanges;
bdpdataadapter1.Fill(DataSet1);
bdpdataadapter2.Fill(DataSet1);
dbWebGrid1.DataBind;
dbWebGrid2.DataBind;
end
//Code
End-------------------------------------------------------------------------
--------------------------------------------------------------------
Thanks in Advance.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads