asp.net - How to retrive the varchar value of SQL SERVER database to an array using c# -


i having database name "fees" have declared different columns tutionfee, computer fee, admissiofee etc.

now want retrieve value of tutionfee array. can use where. using c#

sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["connectionstring"].connectionstring); sqlcommand check = new sqlcommand("select * fees admno = @admno", con); 

if know exact row count of select command, can create string array , use sqldatareader column value in loop.

let's select statement returns 10 row, can use like;

var array = new string[10];  using(var con = new sqlconnection(configurationmanager.connectionstrings["connectionstring"].connectionstring)) using(var check = new sqlcommand("select * fees admno = @admno", con)) {     // add parameter value.      using(var reader = check.executereader())     {        int = 0;        while(reader.read())        {           array[i] = reader.getstring(reader.getordinal("tutionfee"));            i++;        }     } } 

if don't know array size in compile time, can use executescalar select count(*)... command row count first or can use list<string> instead.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -