locked
gridview RRS feed

  • Question

  • Hi All,
     
    I am having two gridview i.e Gridview1 and gridview2.gridview1 have 2 column i.e checkbox and student id. And gridview2 is
    showing details of student based on checked condition on gridview1.
    sqlcommand for girdview2 is:-
    select col1,col2,col3 from student where id=@id

    main problem is I have more than 100 id's so does i need to write like this:-
    select col1,col2,col3 from student where (id=@id1) or (id=@id2) ... upto id=@id100

    or does there is any alernate way possible..please help me.

    Thanks,
    gsr
    Sunday, September 14, 2014 11:10 AM

Answers

  • Hello gsr7,

    >>or does there is any alernate way possible..please help me.

    It seems that you are working with a SQL Server database because I notice you use the SqlCommand class.

    If it is, in SQL Server, there is the IN syntax which would be a better alternate way in your case:

    Contacting your all ids to a string variable as below format:

    string yourids = “’id1’,’id2’,…’id100’”;

    Writting the query as below:

    select col1,col2,col3 from student where id in (“+yourids+”)

    And it is recommended to use the Parameterized Queries which prevents your project from being attacked by SQL injection.

    Best Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Fred Bao Monday, September 15, 2014 9:09 AM
    • Marked as answer by gsr7 Tuesday, September 16, 2014 5:14 PM
    Monday, September 15, 2014 9:09 AM