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