Yama
Wed Jun 02 17:18:59 CDT 2004
Hello William,
Here is more or less what I have:
SqlDataAdapter daTableParent = GetTableParentUpdateAdapter(conn, tx);
SqlDataAdapter daTableChild = GetTableChildUpdateAdapter(conn, tx);
ds is a XSD which contains the relationship between TableParent and
TableChild.
daTableParent.Update(ds.TableParent);
daTableChild.Update(ds.TableChild);
virtual protected SqlDataAdapter GetTableParentUpdateAdapter(SqlConnection
conn, SqlTransaction tx)
{
if(conn == null) throw new ArgumentNullException("conn");
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.InsertCommand = GetTableParentInsertCmd(conn, tx);
adapter.UpdateCommand = GetTableParentUpdateCmd(conn, tx);
adapter.DeleteCommand = GetTableParentDeleteCmd(conn, tx);
return adapter;
}
virtual protected SqlCommand GetTableParentInsertCmd(SqlConnection conn,
SqlTransaction tx) {
if(conn == null) throw new ArgumentNullException("conn");
SqlCommand cmd = new SqlCommand("TableParent_spi", conn, tx);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameterCollection parms = cmd.Parameters;
parms.Add(new SqlParameter("@PID ", SqlDbType.Int, 0,
ParameterDirection.InputOutput, true, 10, 0, "PID", DataRowVersion.Default,
0));
parms.Add("@Description", SqlDbType.NVarChar, 250, "Description");
return cmd;
}
virtual protected SqlCommand GetTableChildUpdateCmd(SqlConnection conn,
SqlTransaction tx) {
if(conn == null) throw new ArgumentNullException("conn");
SqlCommand cmd = new SqlCommand("TableChild_spu", conn, tx);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameterCollection parms = cmd.Parameters;
parms.Add(new SqlParameter("@CID ", SqlDbType.Int, 0,
ParameterDirection.InputOutput, true, 10, 0, "PID", DataRowVersion.Default,
0));
parms.Add("@PID", SqlDbType.Int, 0, "PID");
parms.Add("@Column1", SqlDbType.NVarChar, 250, "Column1");
parms.Add("@Column2", SqlDbType.NVarChar, 250, "Column2");
return cmd;
}
Do the same thing for the GetTableChildUpdateAdapter function. The problem I
am having is how to force a the returned value of PID into its foreign key
constraint in the GetTableChildUpdateCmd's parms.Add("@PID", SqlDbType.Int,
0, "PID");?
(Please take in consideration that I did not include all the function
creating the Data-Adapter.)
They do have relationship in the XSD already...
Thanks,
Yama
"William Ryan eMVP" <dotnetguru@comcast.nospam.net> wrote in message
news:eGE2IoNSEHA.3596@tk2msftngp13.phx.gbl...
> Do you have a DataRelation set up? If so, you just need tocall update on
> the Parent table's adapter, then call it on the child table's adapter. If
> you are getting values back from the db, you can leave on the Refresh
> DataSet option in the configuration wizard (which is sounds like you're
> using) and the values will cascade. However it's critical you have a
> DataRelation in place and you call update on the parent(s) then the
> child(ren).
>
> --
>
> W.G. Ryan, eMVP
>
>
http://forums.devbuzz.com/
>
http://www.knowdotnet.com/williamryan.html
>
http://www.msmvps.com/WilliamRyan/
>
http://www.devbuzz.com/content/zinc_personal_media_center_pg1.asp
> "Yama Kamyar" <ykamyar@3ecompany.com> wrote in message
> news:OYiGZQNSEHA.1392@TK2MSFTNGP09.phx.gbl...
> > Hi,
> >
> > I am trying to update a row in my data-adapter after inserting to a
parent
> > table.
> >
> > Scenario:
> >
> > TableParent
> > --- PID (NOT NULL)
> > --- Description (accept NULL)
> >
> > TableChild
> > --- CID (NOT NULL)
> > --- PID (accept NULL)
> > --- Column1 (accept NULL)
> > --- Column2 (accept NULL)
> > --- etc...
> >
> > when the dataadpter is created and updated how do I update the
TableChild
> > upon inserting a new column to TableParent?
> >
> > Thanks,
> >
> > Yama
> >
> >
> >
> >
>
>