c# - Select from where ID in (an array of my program) -


i want list of items table based on id. list of id need select contain in array or dictionary in program.

so instead of using lot of query :

select * tbldata id=1

select * tbldata id=3

select * tbldata id=9

select * tbldata id=15

... ( thousand of records here) select * tbldata id=50000

select * tbldata id=50100

it's worse performance because of many query need run. there other smarter way ?

use in in where condition.

dim sids string each sid string in dic.keys     sids += sid + "," next  'remove last comma sids = sids.substring(0,sids.length-1)  dim sql string = "select * tbldata id in (" + sids + ")" 

now can execute sql , fill datatable using sql adapter

if values stored in array can use string.join , place in sql query in statement.

dim sids string = string.join(",", arrid) dim sql string = "select * tbldata id in (" + sids + ")" 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -