Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#2.0
How can we declare a generic value in a dynamic query in C#
for eg: now i declare list=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 20: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 at 2-Dec-12 4:40am
@OriginalGriff so is it not possible to add any value in my query?
OriginalGriff at 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
0 OriginalGriff 685
1 Maciej Los 290
2 Richard Deeming 185
3 Suvendu Shekhar Giri 184
4 Abhinav S 166
0 Sergey Alexandrovich Kryukov 9,678
1 OriginalGriff 9,135
2 Peter Leow 5,082
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 2,606

Advertise | Privacy | Mobile
Web01 | 2.8.150327.1 | Last Updated 1 Dec 2012
Copyright © CodeProject, 1999-2015
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