Master \ Detail Table Dataset Add \ Update \ Delete Rows

  • Thread starter Thread starter Mary1982
  • Start date Start date
M

Mary1982

Guest
Pls help me,

SqlCommandBuilder b_invCallers = new SqlCommandBuilder(ad_invCallers);
ad_invCallers.SelectCommand = new SqlCommand("SELECT * FROM invCallers", conn);
ad_invCallers.Fill(dt_invCallers, "invCallers");
SqlCommandBuilder b_invCallersD = new SqlCommandBuilder(ad_invCallersD);
ad_invCallersD.SelectCommand = new SqlCommand("SELECT * FROM invCallersD", conn);
ad_invCallersD.Fill(dt_invCallers, "invCallersD");

dt_invCallers.Relations.Add("invCallersHD",
dt_invCallers.Tables["invCallers"].Columns["unid"],
dt_invCallers.Tables["invCallersD"].Columns["unidH"]);

DataRow mCallerRow = dt_invCallers.Tables["invCallers"].NewRow();
mCallerRow["fileName"] = fileName;
mCallerRow["apiMethod"] = "sendInvoices";
dt_invCallers.Tables["invCallers"].Rows.Add(mCallerRow);

ad_invCallers.UpdateCommand = b_invCallers.GetUpdateCommand();
ad_invCallers.Update(dt_invCallers, "invCallers");

DataRow dCallerRow = dt_invCallers.Tables["invCallersD"].NewRow();
dCallerRow["headid"] = Convert.ToInt64(datasetInvs.Tables[0].Rows[i_invTypes]["unid"]);
dCallerRow["invId"] = Convert.ToInt64(datasetInvs.Tables[0].Rows[i_invTypes]["invId"]);
dCallerRow["fileName"] = fileName;
dCallerRow.SetParentRow(mCallerRow);
dt_invCallers.Tables["invCallersD"].Rows.Add(dCallerRow);
ad_invCallersD.UpdateCommand = b_invCallersD.GetUpdateCommand();
ad_invCallersD.Update(dt_invCallers, "invCallersD");

Pls in .update command I am getting error because foreign field "unidH" has not value.

Continue reading...
 
Back
Top