如何在Asp.Net中使用此Sql命令更新表 [英] How Do I Use This Sql Command In Asp.Net To Update Table
本文介绍了如何在Asp.Net中使用此Sql命令更新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在asp.net中使用此代码更新另一个表格
how to use this code in asp.net to update a table from another one
UPDATE t1 SET t1.[name] = t2.[name], t1.address = t2.address, t1.[date] = t2.[date]
FROM table1 as t1 INNER JOIN table2 AS t2 ON t1.billno = t2.billno
WHERE t1.billno Like 'A100%'
plzz帮我解决这个问题
plzz help me with this
推荐答案
在connectStr中,传递你的连接字符串。
In connectStr, pass your Connection String.
string connectStr = "";//pass your connection string
string updateQuery = "UPDATE T1
SET T1.name = T2.name, T1.address_ = T2.address_
FROM TABLE1 T1
INNER JOIN TABLE2 T2
ON T1.billNo = T2.billNo
WHERE T2.billNo LIKE 'A100%'";
SqlConnection conn = new SqlConnection(connectStr);
SqlCommand cmd = new SqlCommand(updateQuery,conn);
conn.Open();
int result = cmd.ExecuteNonQuery();
conn.Close();
if(result>0)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alertbox", "<script language='javascript'>alert('Updated');</script>");
}
希望这能解决您的问题! :)
Hope this solves your problem!! :)
阅读这篇文章
http://www.onlinebuff.com/article_step-by-step-select-insert-update-and -delete-using-aspnet-c-and-adonet_32.html [ ^ ]
这篇关于如何在Asp.Net中使用此Sql命令更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文