Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,508 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,709 people online right now. Registration is fast and FREE... Join Now!




Variables/Parameters as Field Names and Values

 
Reply to this topicStart new topic

Variables/Parameters as Field Names and Values, I need help in writting an SQL statement which uses parameters or vari

Elven
15 Aug, 2008 - 04:40 AM
Post #1

New D.I.C Head
*

Joined: 13 Aug, 2008
Posts: 7

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:
CODE
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
CODE
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 wink2.gif ).

User is offlineProfile CardPM
+Quote Post

Elven
RE: Variables/Parameters As Field Names And Values
15 Aug, 2008 - 05:20 AM
Post #2

New D.I.C Head
*

Joined: 13 Aug, 2008
Posts: 7

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

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 smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 08:44PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month