Foros del Web » Programación para mayores de 30 ;) » .NET »

Generar un nuevo registro en una BD

Estas en el tema de Generar un nuevo registro en una BD en el foro de .NET en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 16/09/2004, 10:41
Avatar de CarlosAndres  
Fecha de Ingreso: julio-2004
Ubicación: Bogotá, Colombia
Mensajes: 80
Antigüedad: 19 años, 9 meses
Puntos: 0
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?

Última edición por CarlosAndres; 16/09/2004 a las 10:47
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:29.