R
rmontgomery429
Hello all,
I am using strongly typed datasets for my data access. They work
fine except for when I try to insert a new row in a table to get the
next unique id. I have a table for emails. It has columns like
email_id, subject, etc... I have a data table associated with that
table and 95% of the time i have no problem. However sometimes when I
run the following code i get the 'This row already belongs to another
table' exception. Please help.
The error information is as follows:
--Exception information:
Exception type: System.ArgumentException
Exception message: This row already belongs to another table.
--Stack trace:
at System.Data.DataTable.InsertRow(DataRow row, Int32 proposedID,
Int32 pos, Boolean fireEvent)
at System.Data.DataRowCollection.Add(DataRow row)
at EmailDataSet.EmailDataTable.AddEmailRow(EmailRow row)
at Communication_SendEmail.get_EmailID()
at Communication_SendEmail.Page_Load(Object sender, EventArgs e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,
Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
--The code where it errors out:
int? emailID = (int?)Session["emailID"];
if (emailID == null)
{
// Get a new email row
EmailDataSet.EmailRow emailRow = EmailDT.NewEmailRow();
emailRow.DateSent = DateTime.Now;
emailRow.SentBy =
Profile.AppianUser.UserID.ToString().PadLeft(9, '0');
emailRow.SetSubjectNull();
emailRow.SetBodyNull();
EmailDT.AddEmailRow(emailRow); // ERRORS OUT HERE!!!
EmailTableAdapter emailTA = new EmailTableAdapter();
emailTA.Update(EmailDT);
// Get the new email id
emailID = emailRow.EmailID;
// Add the email id to session
Session["emailID"] = emailID;
}
return emailID;
--It errors out on the EmailDT.AddEmailRow(emailRow); line sometimes,
but sometimes not.
--The Email DataTable is as follows:
EmailDataSet.EmailDataTable emailDT =
(EmailDataSet.EmailDataTable)Cache["emailDT"];
if (emailDT == null)
{
emailDT = new EmailDataSet.EmailDataTable();
EmailTableAdapter emailTA = new EmailTableAdapter();
emailTA.Fill(emailDT);
Cache.Insert("emailDT", emailDT, null,
DateTime.Now.AddMinutes(30), TimeSpan.Zero);
}
return emailDT;
I can't figure out why it works fine most of the times however it
throws that exception every now and then...seems weird to me and I
can't put my finger on it. Please help!
Thank you.
I am using strongly typed datasets for my data access. They work
fine except for when I try to insert a new row in a table to get the
next unique id. I have a table for emails. It has columns like
email_id, subject, etc... I have a data table associated with that
table and 95% of the time i have no problem. However sometimes when I
run the following code i get the 'This row already belongs to another
table' exception. Please help.
The error information is as follows:
--Exception information:
Exception type: System.ArgumentException
Exception message: This row already belongs to another table.
--Stack trace:
at System.Data.DataTable.InsertRow(DataRow row, Int32 proposedID,
Int32 pos, Boolean fireEvent)
at System.Data.DataRowCollection.Add(DataRow row)
at EmailDataSet.EmailDataTable.AddEmailRow(EmailRow row)
at Communication_SendEmail.get_EmailID()
at Communication_SendEmail.Page_Load(Object sender, EventArgs e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,
Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
--The code where it errors out:
int? emailID = (int?)Session["emailID"];
if (emailID == null)
{
// Get a new email row
EmailDataSet.EmailRow emailRow = EmailDT.NewEmailRow();
emailRow.DateSent = DateTime.Now;
emailRow.SentBy =
Profile.AppianUser.UserID.ToString().PadLeft(9, '0');
emailRow.SetSubjectNull();
emailRow.SetBodyNull();
EmailDT.AddEmailRow(emailRow); // ERRORS OUT HERE!!!
EmailTableAdapter emailTA = new EmailTableAdapter();
emailTA.Update(EmailDT);
// Get the new email id
emailID = emailRow.EmailID;
// Add the email id to session
Session["emailID"] = emailID;
}
return emailID;
--It errors out on the EmailDT.AddEmailRow(emailRow); line sometimes,
but sometimes not.
--The Email DataTable is as follows:
EmailDataSet.EmailDataTable emailDT =
(EmailDataSet.EmailDataTable)Cache["emailDT"];
if (emailDT == null)
{
emailDT = new EmailDataSet.EmailDataTable();
EmailTableAdapter emailTA = new EmailTableAdapter();
emailTA.Fill(emailDT);
Cache.Insert("emailDT", emailDT, null,
DateTime.Now.AddMinutes(30), TimeSpan.Zero);
}
return emailDT;
I can't figure out why it works fine most of the times however it
throws that exception every now and then...seems weird to me and I
can't put my finger on it. Please help!
Thank you.