Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 26-Jul-11 1:03am
v2
Comments
Dylan Morley 26-Jul-11 6:14am    
Post your SQL statement, will help us determine the problem

Use the 'Improve Question' option to edit your original post
Member 8112988 26-Jul-11 6:15am    
update UserChannelRights set FormUpdated='"+ DateTime.Now +"', channelname='" + channelname + "' where UserId=" + userId

The Channel name not updating
Member 8112988 26-Jul-11 6:18am    
my chanel name input like "23|2|45|90|"

1 solution

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

VB
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()


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900