ADO.Net - how to get data from database and bind to the
controls -- write this small code

Answer Posted / kinjal panchal

first of all write namespace in your page.
using Syste.data.sqlclient;

//code
sqlconnection cn=new sqlconnection();
cn.open();
sqlcommand cmm=new sqlcommand("write select query here",cn);
sqldataAdupter da=new sqldataAdupter(cmm);
datatable dt=new datatable();
da.fill(dt);
cn.close();

suppose u have gridview control then

gridview.datasource=dt;
gridview.databind();

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which method do you use to enforce garbage collection in .net?

697


Explain global assembly cache.

760


What’s difference between “optimistic” and “pessimistic” locking?

774


What are the differences between clr & cts?

719


How can you use a custom controls in ASP.NET application?

711


In which event of the page life cycle, is the viewstate available?

683


Can you explain why it is useful to use mvc instead of webforms? : asp.net mvc

764


Tell me how asp.net mvc differs from asp.net web forms? : asp.net mvc

788


What does clearing cache?

698


For which does this Codebehind="MyCode.aspx.cs" is relevent to ?

787


Explain difference betn dataset and recordset?

682


What is HTTPModule and HTTPcontext? What is the use of each?

2188


How you will handle session when deploying application in more than a server?

816


What parameters can you pass in the url of the api? Can get and post use the same url?

725


How you can manage the state of application at the server side in ASP.NET?

778