更新查询中的函数调用 [英] funtion call in update query
本文介绍了更新查询中的函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建windows表单application.i必须使用另一种形式定义的功能如何在更新查询中调用。
更新mytable set id = 1其中name =?(这里我想调用一个函数,即fetchname())
解决方案
调用函数,并将返回的值作为参数添加:
< pre lang =c#> 使用(SqlConnection connection = new SqlConnection( 您的连接字符串))
使用(SqlCommand command = new SqlCommand( UPDATE mytable SET id = 1 WHERE name = @name,connection))
{
command.Parameters.AddWithValue( @ name,fetchname());
connection.Open();
command.ExecuteNonQuery();
}
i am building windows form application.i have to use funtion which is defined in another form how can i call in update query.
"update mytable set id=1 where name=?(here i want to call a funtion i-e fetchname())
解决方案
Call the function, and add the returned value as a parameter:
using (SqlConnection connection = new SqlConnection("YOUR CONNECTION STRING HERE")) using (SqlCommand command = new SqlCommand("UPDATE mytable SET id = 1 WHERE name = @name", connection)) { command.Parameters.AddWithValue("@name", fetchname()); connection.Open(); command.ExecuteNonQuery(); }
这篇关于更新查询中的函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文