Foros del Web

Foros del Web (http://www.forosdelweb.com/)
-   .NET (http://www.forosdelweb.com/f29/)
-   -   Generar un nuevo registro en una BD (http://www.forosdelweb.com/f29/generar-nuevo-registro-bd-231964/)

CarlosAndres 16/09/2004 10:41

Generar un nuevo registro en una BD
 
Buenas:
Quiero insertar un nuevo registro en una base de datos de la siguiente forma:


OracleConnection oc = new OracleConnection();
oc.ConnectionString = @ConfigurationSettings.AppSettings["connectionString"];
oc.Open();
NwHistAdapter = new OracleDataAdapter("select * from SUBJECT_HISTORY us where us.SUBJECT_ID =" + strParent ,oc);
histCmdBuilder = new OracleCommandBuilder(NwHistAdapter);
histDataSet = new DataSet("histDataSet");
NwHistAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
NwHistAdapter.Fill(histDataSet, "SUBJECT_HISTORY");
DataRow dtrNewHist = histDataSet.Tables["SUBJECT_HISTORY"].NewRow();

dtrNewHist["SUBJECT_ID"]=strParent.ToString();
dtrNewHist["HISTORY_DATE"]=DateTime.Now;
dtrNewHist["DESCRIPTION"]=txtDescription.Text;
dtrNewHist["SUB_USER_ID"]=1;
dtrNewHist["LAST_CONTACT_DAY"]=txtLast.Text;
dtrNewHist["NEXT_ACTION_DATE"]=txtNext.Text;
dtrNewHist["ACTION_ID"]=txtNext_action.Text;
dtrNewHist["EFFECT_ID"]="24";
dtrNewHist["DURATION"]=12;
dtrNewHist["SUB_CONTACT_ID"]=strId;
dtrNewHist["SERVICE_ID"]=txtService.Text;

histDataSet.Tables["SUBJECT_HISTORY"].Rows.Add(dtrNewHist);
histDataSet.AcceptChanges();
NwHistAdapter.Update(histDataSet,"SUBJECT_HISTORY" );


Pero me aparece el siguiente error:
Server Error in '/EasySales' Application.
--------------------------------------------------------------------------------

ORA-02291: integrity constraint (ECMV2.SERVICE_CUSTOMER_HISTORY_FK1) violated - parent key not found
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Oracle.DataAccess.Client.OracleException: ORA-02291: integrity constraint (ECMV2.SERVICE_CUSTOMER_HISTORY_FK1) violated - parent key not found

Source Error:


Line 158: histDataSet.Tables["SUBJECT_HISTORY"].Rows.Add(dtrNewHist);
Line 159: //histDataSet.AcceptChanges();
Line 160: NwHistAdapter.Update(histDataSet,"SUBJECT_HISTORY" );
Line 161:
Line 162:


Source File: e:\easysales\easysales\wfnewhistory.aspx.cs Line: 160

Stack Trace:


[OracleException: ORA-02291: integrity constraint (ECMV2.SERVICE_CUSTOMER_HISTORY_FK1) violated - parent key not found]
System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) +1667
Oracle.DataAccess.Client.OracleDataAdapter.Update( DataRow[] dataRows, DataTableMapping tableMapping) +9
System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) +152
EasySales.WFSaveHistory.salvar(String strId, String strParent) in e:\easysales\easysales\wfnewhistory.aspx.cs:160
EasySales.WFSaveHistory.btnSave_Click(Object sender, EventArgs e) in e:\easysales\easysales\wfnewhistory.aspx.cs:97
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
Según lo que he leido tiene que ver con las llaves que estan contenidas en las otras tablas.

¿Me equivoco? , alguien puede ayudarme porfavor , aunque tenga que hacerlo on un INSERT INTO en vez del OracleCommandBuilder?


La zona horaria es GMT -6. Ahora son las 06:43.

Desarrollado por vBulletin® Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.