ziorrinfotech
asked on
how to insert one row at a time from each table exits in dataset
I am reading one XML file and storing data in 5 different datable, now these are related to each other.
here is my req.
I want to insert one row of each table a time, so that one complete node can be inserted in to the database.
and also I want to make sure that if some records contains error then all the records before this records must be committed or permanently stored into the database.
right now i am using transaction and looping of each records some thing like shown below.
I want to know is there is any proper or good way to do this.
here is my req.
I want to insert one row of each table a time, so that one complete node can be inserted in to the database.
and also I want to make sure that if some records contains error then all the records before this records must be committed or permanently stored into the database.
right now i am using transaction and looping of each records some thing like shown below.
I want to know is there is any proper or good way to do this.
_transaction = _connection.BeginTransaction();
try {
// InsertAudit(sourceID);
foreach(DataRow PArow in _dataset.Tables["ProductCategory"].Rows) {
if (CheckRecords(PArow,"ProductCategory") == false) {
InsertProductCategory(PArow);
}
foreach (DataRow Productrow in _dataset.Tables["Product"].Rows) {
if (PArow["OID"].ToString() == Productrow["PrductCatID"].ToString()){
if (CheckRecords(Productrow, "Product") == false) {
InsertProduct(Productrow);
}
foreach (DataRow IssueProductrow in _dataset.Tables["IssueProduct"].Rows) {
if (Productrow["OID"].ToString() == IssueProductrow["ProductID"].ToString()) {
if (CheckRecords(IssueProductrow, "IssueProduct") == false) {
InsertIssueProduct(IssueProductrow);
}
}
}
}
}
}
foreach (DataRow Issuerow in _dataset.Tables["Issue"].Rows) {
if (CheckRecords(Issuerow, "Issue") == false) {
InsertIssue(Issuerow);
foreach (DataRow IssueProductXIssuerow in _dataset.Tables["IssueProductXIssue"].Rows) {
if (Issuerow["OID"].ToString() == IssueProductXIssuerow["IssueID"].ToString()) {
InsertIssueProductXIssue(IssueProductXIssuerow);
}
}
}
}
foreach (DataRow rowArticle in _dataset.Tables["Article"].Rows) {
if (Convert.ToInt16(rowArticle["Inserted"]) == 1) {
CheckRecords(rowArticle, "Article");
InsertArticle(rowArticle);
foreach (DataRow rowAV in _dataset.Tables["ArticleVersion"].Rows) {
if (rowArticle["OID"].ToString() == rowAV["ArticleID"].ToString()) {
CheckRecords(rowAV, "ArticleVersion");
InsertArticleVersion(rowAV);
foreach (DataRow rowPA in _dataset.Tables["ProjectAudience"].Rows) {
if (rowAV["OID"].ToString() == rowPA["ArticleVersionID"].ToString()) {
CheckRecords(rowPA, "ProjectAudience");
InsertProjectAudience(rowPA);
}
}
foreach (DataRow rowAC in _dataset.Tables["ArticleContent"].Rows) {
if (rowAV["OID"].ToString() == rowAC["ArticleVersionID"].ToString()) {
CheckRecords(rowAC, "ArticleContent");
InsertArticleContent(rowAC);
}
}
foreach (DataRow rowImages in _dataset.Tables["Images"].Rows) {
if (rowAV["OID"].ToString() == rowImages["ArticleVersionID"].ToString()) {
CheckRecords(rowImages, "Images");
InsertImages(rowImages);
}
}
}
}
}
}
_transaction.Commit();
} catch(Exception e) {
_transaction.Rollback();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
how can i do this