How to assing values to 2 dimensional array with data from database in asp.net using c#? -


suppose sql database studentinfo , table name registration

id----------name---------------email---------------------------phoneno 1           munasunghe        amilamunasinghe@yahoo.com        0717069425     2           liyanarachchi     hareshliya6@gmail.com            0756706352  

protected void page_load(object sender, eventargs e) {     string query = "select id, name, email, phoneno registration";      sqlcommand cmd1 = new sqlcommand(query);     datatable dt1 = getdata(cmd1);     int rowcount = dt1.rows.count;     /* want assing dt1 datatable data 2 dimensional array*/  } 

the function getdata used data database.

 private datatable getdata(sqlcommand cmd)     {         datatable dt = new datatable();         string strconnstring = system.configuration.configurationmanager.connectionstrings["constring"].connectionstring;         sqlconnection con = new sqlconnection(strconnstring);         sqldataadapter sda = new sqldataadapter();         cmd.commandtype = commandtype.text;         cmd.connection = con;         try         {             con.open();             sda.selectcommand = cmd;             sda.fill(dt);             return dt;         }         catch         {             return null;         }                 {             con.close();             sda.dispose();             con.dispose();         }     } 

please give example code me.

    object[,] target = new object[dt1.rows.count, dt1.columns.count];       int rowcount = 0;      foreach(datarow dr in dt1.rows)         foreach(datacolumn dc in dt1.columns)         {              target[rowcount, dc.ordinal] = dr[dc];             rowcount++;         } 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -