c# - Populate DataTable with records from database? -


this method data datatable

private function getdata() pageddatasource ' declarations     dim dt new datatable dim dr datarow dim pg new pageddatasource  ' add columns     dt.columns.add("column1") dt.columns.add("column2")  ' add test data     integer = 0 10     dr = dt.newrow     dr("column1") =     dr("column2") = "some text " & (i * 5)     dt.rows.add(dr) next  ' add dataview datatable pageddatasource   pg.datasource = dt.defaultview  ' return datatable     return pg  end function  

it returns datatable "pg"

what changes must make method records table in database?

c# examples great see reply code , changes....

if linq sql not option can fall ado.net. need create connection database , create , run command retrieve data require , populate datatable. here example if c#:

// create connection database         sqlconnection conn = new sqlconnection("data source=mydbserver;initial catalog=mydb;integrated security=true"); // create command extract required data , assign connection string sqlcommand cmd = new sqlcommand("select column1, colum2 mytable", conn); cmd.commandtype = commandtype.text; // create dataadapter run command , fill datatable sqldataadapter da = new sqldataadapter(); da.selectcommand = cmd; datatable dt = new datatable(); da.fill(dt); 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -