This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.
| 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: 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
Useful Resources
|
|
| 2. |
What is serialization? Write an example program to serialize a DataSet. |
|
Answer» Serialization is the method of converting an object into a byte stream which can be stored as well as transmitted over the network. The advantage of serialization is that data can be transmitted in a cross-platform environment ACROSS the network and also it can be saved in a storage MEDIUM like persistent or non-persistent. The code for SERIALIZING a DataSet is: using SYSTEM;using System.Data;using System.Data.SqlClient;using System.Xml.Serialization;using System.IO;public partial class Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("Data Source=data_source_name;Initial Catalog=employee;Integrated Security=True"); //Create connection object SqlDataAdapter da = new SqlDataAdapter("select * from emp", conn); //DataAdapter creation DataSet s = new DataSet(); da.Fill(s); FileStream fObj = new FileStream("C:\\demo.xml", FileMode.Create); // Create a XML file XmlSerializer sObj = new XmlSerializer(typeof(DataSet)); sObj.Serialize(fObj, s); //Serialization of a DataSet fObj.Close(); }}In the above given example, the database NAME is employee and, the table name is emp. The data in a DataSet will be serialized and stored in a demo.xml file by using Serialize() method. |
|
| 3. |
How to make SQL Server connection in ADO.NET? |
|
Answer» Consider the below example where a CONNECTION to the SQL Server has been established. An employee database will be used to connect. The C# code will be: using (SqlConnection CON = new SqlConnection(connectionString)) { con.Open(); }Using block will be useful in closing the connection automatically. It is not required to explicitly call the CLOSE() method, because using block will do this implicitly when the code exits the block. // ConnectionExample.csusing System; using System.Data.SqlClient; namespace ConsoleApplicationExample { class ConnectionExample { STATIC void Main(string[] args) { new Program().ConnectingMethod(); } public void ConnectingMethod() { using ( // Creating Connection SqlConnection CONN = new SqlConnection("data source=.; database=employee; integrated security=SSPI") ) { conn.Open(); Console.WriteLine("Connection Has Been Successfully Established."); } } } }Output: Connection Has Been Successfully Established.Press any key to continue...On execution, if the connection has been established, a message will be displayed on an output window. If the connection is not created with the help of using a block, a connection must be closed explicitly. |
|
| 4. |
Which methods are provided to add or remove rows from the DataTable object? |
|
Answer» The collection of rows for the DATATABLE object has been defined by the DataRowCollection class. DataRowCollection class has the method NewRow() for adding a NEW DataRow to DataTable. This method creates a new row that implements the similar SCHEMA that is applied to the DataTable. The methods provided by the DataRowCollection object are given below:
|
|
| 5. |
What is the difference between Dataset.Clone() and DataSet.Copy() methods? |
Answer»
|
|
| 6. |
How can you identify whether any changes are made to the DataSet object since the time it was last loaded? |
|
Answer» The DataSet object has two methods to TRACK down the CHANGES:
Use the RejectChanges() method, if you want to reverse the entire changes since from the time the DataSet object was loaded. |
|
| 7. |
What is LINQ? |
Answer»
|
|
| 8. |
What is the difference between connected and disconnected architecture in ADO.NET? |
||||||||||||||
Answer»
|
|||||||||||||||
| 9. |
How to load multiple tables into a dataset? |
|
Answer» DataSet ds=new DataSet();SQLCONNECTION con=new SqlConnection("connection_string");SqlDataAdapter da=new SqlDataAdapter("select * from Employee1",con);da.Fill(ds.Tables.Add()); da=new SqlDataAdapter("select * from Employee2",con);da.Fill(ds.Tables.Add()); After tables have been added into a DataSet, the below-given code TELLS about how to make use of the DataSet tables. If you decide to use the first table in a dataset or to copy the table data into a data table, then follow the below-given code: DATATABLE dt=new DataTable();dt=ds.Tables[0];The above code can be USED to add the required number of tables in a dataset. This ensures connection-less access to data. As the dataset is filled with multiple tables, every time we want to query the data the database connection is not required. It also makes sure about the reusability of data. |
|
| 10. |
What is Response.Expires and Response.ExpiresAbsolute property? |
Answer»
|
|
| 11. |
What are the different authentication techniques used to connect with MS SQL Server? |
|
Answer» Before performing any task in the database, SQL Server will authenticate. Two types of authentication techniques are:
The below-given ConnectionString specifies Mixed mode authentication: C#"Persist Security Info=False;User ID=Harsh;Password=xyz@123;Initial Catalog=Institute;Server=MySqlServer" |
|
| 12. |
Explain about ADO.NET objects. |
|
Answer» There are seven main objects in ADO.NET. They are:
|
|
| 13. |
Explain about ExecuteScalar() in ADO.NET. |
Answer»
Here, we create an object of the class SqlConnection and SqlCommand. We pass SQL Statement to the object of SqlCommand class, which returns a single value. When ExecuteScalar() function gets executed, a single value will be returned, i.e, the total salary of employees. This value will be displayed using a message box. |
|
| 14. |
Briefly explain connected and disconnected architecture of ADO.NET. |
|
Answer» CONNECTED Architecture:
Disconnected Architecture:
|
|
| 15. |
Explain ADO.NET Architecture. |
|
Answer» ADO.NET is based on an Object Model where data residing in the database is accessed using a data provider. It is a technology of data access given by the Microsoft .Net Framework, which helps to communicate between relational and non-relational systems using a common group of components. The components of ADO.NET architecture are:
|
|