Variables/Parameters as Field Names and Values

I need help in writting an SQL statement which uses parameters or vari

Page 1 of 1

1 Replies - 614 Views - Last Post: 15 August 2008 - 06:20 AM Rate Topic: -----

#1 Elven  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-August 08

Variables/Parameters as Field Names and Values

Post icon  Posted 15 August 2008 - 05:40 AM

Heya,

I am working on a code which will allow users to upload images, but unlike most other projects, I do not need to know which user uploaded it, but for which section it was meant and whether it is a first picture, second or 6th...

Current code I am using is following:
SqlCommand command = new SqlCommand( "UPDATE Web SET '" + imgName + "' = @img_data WHERE Strana = 'HomeStrana' ", connection );



Web = database name

imgName is string variable which equals to the text of textbox for inputing image name (later on I plan to make a check whether some of the image fields is empty for that category and if yes, put first empty picture field as a default value here)

@img_data is a parameter which holds the actual picture

Strana = category where it should be uploaded.

I tried using
SqlCommand command = new SqlCommand( "UPDATE Web SET @img_name = @img_data WHERE Strana = 'HomeStrana' ", connection );

as well, but it kept saying "image is incompatible with varchar" meaning he thinks I want to put value of @img_data into @img_name... but I just want him to use @img_name as field name and @img_data as value which needs to be inserted into that field.

Thanks in advance (will thank later of course as well ;) ).

Is This A Good Question/Topic? 0
  • +

Replies To: Variables/Parameters as Field Names and Values

#2 Elven  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-August 08

Re: Variables/Parameters as Field Names and Values

Posted 15 August 2008 - 06:20 AM

OK figured it out. I messed up because I didn't close quoation marks before doing +. :)

I'd like to delete this topic, but not sure how cause I didn't see an option for that. If moderator could do it for me, would appreciate it :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1