0
A
回答
0
使用以下查询:
query = "Create Table #PaperTypeMapping(LaminationTitleId int, PaperTypeId int)";
//For each value of Paper Type Id you will need to insert a row
query = "Insert Into #PaperTypeMapping(LaminationTitleId, PaperTypeId) Values(@laminationId, @paperTypeId)";
//Update existing values
query = "Update OldMapping Set OldMapping.ActiveStatus = 1 FROM LaminationTitleRelation OldMapping Inner join #PapertTypeMapping NewMapping ON OldMapping.LamTitleId = NewMapping.LaminationTitleId and OldMapping.PaperTypeId = NewMapping.PaperTypeId"
//Insert new values
query = "Insert into LaminationTitleRelation(lamTitleId, PapertTypeId, ActiveStatus) Select LaminationTitleId, PapertTYpeId, 1 From #PaperTypeMapping NewMapping where NOT EXISTS(SELECT 1 FROM LaminationTitleRelation OldMapping WHERE OldMapping.LamTitleId = NewMapping.LaminationTitleId and OldMapping.PaperTypeId = NewMapping.PaperTypeId)";
或者你也可以使用下面的链接一个由MS SQL内置的实用工具Merge
-1
protected void btnUpdate_Click(object sender, EventArgs e) {
DB = new DBFunctions();
string vItems = mGetSelectedItems();
string vQuery = "Update laminationtitle Set title='" + txtLaminationTitle.Text + "',laminationtypeid='" + ddlProductType.SelectedValue + "' where laminationid='" + Request.QueryString["laminationid"] + "'";
int x = DB.SetData(vQuery);
DataTable dSelect = new DataTable();
DataTable dAll = new DataTable();
DB = new DBFunctions();
DB1 = new DBFunctions();
if (x > 0) {
int y = DB.SetData("delete from laminationtitlepapertyperelation where lamtitleid=" + Request.QueryString["laminationid"]);
if (y > 0) {
string[] values = vItems.Split(',');
for (int i = 0; i < values.Length; i++) {
vQuery = "insert into laminationtitlepapertyperelation(lamtitleid, papertypeid, activestatus)VALUES('" + Request.QueryString["laminationid"].ToString() + "','" + values[i] + "',1)";
DB.SetData(vQuery);
ScriptManager.RegisterStartupScript(this, GetType(), " Update Lamination Title", "alert('Lamination " + '"' + txtLaminationTitle.Text + '"' + " Title Updated Sucessfully');window.location='ManageLaminationTitle.aspx';", true);
}
}
}
}
相关问题
- 1. 与下一个相同的id的值更换零 - MySQL的
- 2. 从两个表中更新值相同的pcode和ID
- 3. xmlstarlet更新值相同的元素值
- 4. 如果id相同,NoSqlEntityManager.put会更新吗?
- 5. 更改ID,以相同的ID,如果其它的值是相同
- 6. 更新ID与3个相关的实体ID的
- 7. 用不同的ID更新下一个输入,具有相同的值
- 8. 更新来自不同表中的所有值具有相同的id
- 9. jQuery中处理多个ID和更新只相同的ID
- 10. 更新与动态Ajax相同的div
- 11. 更新与LIKE相同的表
- 12. 更新具有相同值的30K行
- 13. 使用相同的变量更新值
- 14. 具有相同表值的MySQL更新
- 15. 更新document.getElementById为不同的div中相同的id名称
- 16. 更新表ID与其他表中的相关ID
- 17. 更新列具有一定价值列值具有相同的ID
- 18. Mongo更新记录与值设置在相同的查询
- 19. SQL更新与相同值的多个行
- 20. 更新ID列与随机值
- 21. 与具有相同ID
- 22. mysql:更新相同值的列中的行更改值
- 23. 更新具有相同值的行是否实际更新行?
- 24. 更新字段mysql表中的值来自其他行的相同产品ID
- 25. 以相同的id实时更新javascript中的文本
- 26. 什么是更新三张相同ID的图像的逻辑?
- 27. 实时更新:通知包含uid和ID,但价值是相同的
- 28. 更新选择框当DIV单击具有相同的id和值
- 29. 更新相同的行
- 30. 不同值的多行上的相同列上的更新
那么这就是你'想做'?但到目前为止,'你做了什么'? – niksofteng
发布您的代码! –
嗨杰夫thanx的回复.......我用不同的方式来解决这个问题...而不是更新记录这是更困难的.....我直接删除/删除表中的记录和防火插入查询删除查询成功....如果删除查询返回TRUE,插入将触发,所有新记录将添加到表中 –