update 问题 update set 字段名=""这里的字段名要用变量表示怎么办? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string str = "update table set col='" + TextBox1.Text +"'";是这个意思么 c#string strname = "bb";string sql = "update tb set name='"+strname+"'";sqldeclare @strname varchar(50)set @strname='bb'update tb set name=@strname或exec('update tb set name='''+@strname+'''') 比如 string id="";update tb set id=""是字段名 create table tb(name varchar(50))insert into tb select 'a'declare @colname varchar(50)set @colname='name'exec('update tb set '+@colname+'=''bb''') select * from tbbb 如果你更新到库里的是字符串的话,你要这样写update set 字段名='"+变量名+"';如果是数值型的要:update set 字段名="+变量名+"; 要看你的SQL语句是在哪儿产生的,如果你是在C#代码中动态组装的,那如下:string id="字段名"; string sValue = "字段值";string sqlStr = "update tb set " + id + "=" + sValue;如果是你的变量是指数据库中的,比如在写数据库函数或存储过程,那如下:declare @colname varchar(50)set @colname='name'exec('update tb set '+@colname+'=''bb''') 当然,如果你不想组装SQL语句,那就使用游标,把变量做为参数传给游标. 拼接一个字符串然后使用系统存储过程:sp_executesql 就可以达到效果...... C# window窗体程序写完后如何把程序和数据库打包生成安装文件 vs2008 自定义快捷键不能用 dataset vc回调函数 改成c# c# 自定义控件如何在属性栏添加自定义事件?可以双击生成+=代码? 求Dundas Gauge for ASP.NET(for windows) Version 1.6 Visual Studio 2005安装key 关于权限控制 数据库中数据大量Copy问题 Silverlight部署到IIS上连接不上数据库 升级到 .NET 4.6以上之后bin目录下多出一大堆dll 如何计算精确的时间? 一个导航功能 请帮帮忙
string str = "update table set col='" + TextBox1.Text +"'";是这个意思么
string strname = "bb";
string sql = "update tb set name='"+strname+"'";sql
declare @strname varchar(50)
set @strname='bb'update tb set name=@strname
或
exec('update tb set name='''+@strname+'''')
update tb set id=""
是字段名
insert into tb select 'a'declare @colname varchar(50)
set @colname='name'
exec('update tb set '+@colname+'=''bb''') select * from tbbb
update set 字段名='"+变量名+"';
如果是数值型的要:
update set 字段名="+变量名+";
string id="字段名";
string sValue = "字段值";
string sqlStr = "update tb set " + id + "=" + sValue;
如果是你的变量是指数据库中的,比如在写数据库函数或存储过程,那如下:
declare @colname varchar(50)
set @colname='name'
exec('update tb set '+@colname+'=''bb''')
当然,如果你不想组装SQL语句,那就使用游标,把变量做为参数传给游标.
然后使用系统存储过程:sp_executesql 就可以达到效果......