- .net asp .net how to use data grid view dynamic data in data grid view how to implement datagridview
1) Establish connection to database :
SqlConnection conObj = new SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=F:\WindowsFormsApplication5\WindowsFormsApplication5\StudentDatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
Note :
- SqlConnection Class found in "System.Data.SqlClient" Namespace, So that you need to specify ( using System.Data.SqlClient; ) namespace
2) Create string based on what data need to Display :
String selectString="SELECT * FROM employee";
3) Execute above string :
SqlDataAdapter dataAdapterObj = new SqlDataAdapter(selectString, conObj);
Note :
Note :
- SqlDataAdapter constructor execute selectString and store result in dataAdapterObj
- Require two input selectstring to execute and connection object (conObj)
4)Attach data from dataAdapterObject to DataTable object :
DataAdapter dtObj=new DataAdapter();
dtObj.fill(dataAdapterObj );
5)Finally Attach data from data table (dtObj) to DataGridView using DataSource Property :
datagridview1.DataSource=dtObj;
I hope you got it... If you have any query then ask me...
SAMPLE :
Some more details on...Datagridview database operations
ReplyDeleteLing