SQL Server更新问题 [英] Sql Server Update issue

查看:55
本文介绍了SQL Server更新问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,
尝试运行更新语句时遇到问题.
所有列都在更新,但只有1个列未更新,其数据类型为nvarcher(500).

当我重命名该列的更新但不更新该特定名称时,我已经在很多地方使用了该列,因此无法重命名该列.

Dear All,
I am facing a problem when try to run the update statement.
All columns are updating but only 1 column not update its datatype is nvarcher(500).

When i rename the column its update but for that particular name its not updating , i have use that column in many place so cannot rename that column .

update UserChannelRights set FormUpdated=''"+ DateTime.Now +"'', channelname=''" + channelname + "'' where UserId=" + userId 



频道名称未更新,我怎么知道此列已锁定或是什么?

请提出建议..

在此先感谢



The Channel name not updating, how can i know is this column is locked or what ?

Please suggest ..

Thanks in advance

推荐答案

它看起来不像您正在使用SQL参数,因此请考虑本文

http://weblogs.sqlteam.com/jeffs/archive/2006/07/21/10728.aspx [ ^ ]

您应该始终使用参数,而不是像您一样尝试构建字符串.这在VB中(摘自文章!),但它应该向您展示如何使用参数而不是连接字符串来执行

It doesn''t look like you''re using SQL parameters, so please consider this article

http://weblogs.sqlteam.com/jeffs/archive/2006/07/21/10728.aspx[^]

You should always use parameters, rather than trying to build strings like you have. This is in VB (copied from the article!) but it should show you how you can use parameters rather than concatenating a string to execute

Dim cm As New SqlCommand("", YourConnection)
cm.CommandText = "update UserChannelRights set FormUpdated=@UpdateTime, channelname=@ChannelName where UserId=@UserID"
cm.Parameters.Add("@UpdateTime", SqlDbType.DateTime).Value = DateTime.Now
cm.Parameters.Add("@ChannelName", SqlDbType.NVarChar).Value = channelname 
cm.Parameters.Add("@UserID", SqlDbType.Int).Value = userid

cm.ExecuteNonQuery()



这通常可以解决许多可能发生的问题(例如日期转换),也可以保护您免受SQL注入的侵害.



This often solves a number of problems (e.g. date conversion) that can occur and will also protect you from SQL injection.


这篇关于SQL Server更新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆