Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0
Hi
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
good
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!
  Permalink  
Comments
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 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 1 Dec 2012
Copyright © CodeProject, 1999-2014
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