Click here to Skip to main content
13,051,404 members (48,377 online)
Rate this:
Please Sign up or sign in to vote.
See more:
How can we declare a generic value in a dynamic query in C#
for eg: now i declare list<gllist>=new List>gllist>

now how to declare a value from that list?(there are 3 values say a,b,c)

sql="select * from " +tablename+ "where value= " +genreiclist value(here i want to put the generic list value)+
Posted 30-Nov-12 19:08pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

First off, do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

Second, there are a number of ways to access the content of a List<T> - the simplest of which is to use the index:
obj o0 = myList[0];
obj o1 = myList[1];
There is also the Find method[^] and no end of Linq methods you could use.

Sorry to be a bit vague, but your question is very vague as well!
Nihal Hussain 2-Dec-12 4:40am
@OriginalGriff so is it not possible to add any value in my query?
OriginalGriff 2-Dec-12 4:44am
It probably is, but I'm not sure exactly what you are having problems with.
Can you explain to me in more detail?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 1 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100