1.

Give an example code to fill the GridView by using the object of DataTable during runtime.

Answer»

using System;using System.Data;public partial class Default : System.Web.UI.Page{ protected void Page_Load(object sender, EVENTARGS e) { GRIDVIEW gridView1=new GridView(); //Create GridView object DataTable t = new DataTable("Employee"); // Create the table object DataColumn c = new DataColumn(); //Creating table column DataRow r; //Instance of row c.ColumnName = "EmpID"; //Heading of the coloumn c.DataType = Type.GetType("System.Int32"); //Set the data type of EmpID as an Integer t.Columns.Add(c); //ADDING a column to data table c = new DataColumn(); c.ColumnName = "EmpName"; c.DataType = Type.GetType("System.String"); //Set the type of EmpName as String t.Columns.Add(c); for (int i = 0; i < 5; i++) //This code will create 5 rows { r = t.NewRow(); //Add Column values r["EmpID"] = i; r["EmpName"] = "Employee " + i; t.Rows.Add(r); } gridView1.DataSource = t; //Set gridView1 Datasource as DataTable t gridView1.DataBind(); //Bind Datasource to gridview }}

Output:

Conclusion

ADO.NET is a brilliant technology that was DEVELOPED by Microsoft on the framework of .NET. The primary role and responsibility of ADO.NET technology is to setup a bridge between backend language and your database. A good EXPERIENCE of this technology will be of great use from a development point of view.

ADO.NET technology will definitely help in your career growth as it has quite a good scope. Also learning this interesting technology will always be great fun. ADO.NET along with the knowledge of databases will definitely be exceptional from a growth perspective.

References

  • “Microsoft® ADO.NET 4 Step by Step” by Tim Patrick
  • “ADO.NET in a nutshell” by Bill Hamilton
  • ADO.NET Documentation

Useful Resources

  • C# Interview
  • ASP.NET Interview
  • Microsoft Interview
  • SQL Interview


Discussion

No Comment Found