C# Unit - V
C# Unit - V
2 Marks
1. What is ADO .Net? (Nov 2018)
ADO.NET is a set of classes that expose data access services to the .NET programmer.
ADO.NET provides a rich set of components for creating distributed, data-sharing applications.
It is an integral part of the .NET Framework, providing access to relational data, XML, and
application data. ADO.NET supports a variety of development needs, including the creation of
front-end database clients and middle-tier business objects used by applications, tools, languages,
or Internet browsers.
Perform extensive processing on data without requiring an open connection to the data
source, which frees the connection to be used by other clients.
5. How do you compile and run the ADO.NET sample application?
1. Using Notepad or another text editor, create a blank text file named sample.vb for Visual
Basic sample code or named sample.cs for C# sample code.
2. Copy and paste the Visual Basic or C# sample code from this topic into the blank text
file. Save the file.
3. Open a command prompt (Start, then Run, then enter "command").
4. In the command prompt, change the directory to the directory that contains the new text
file. For example:
cd\SampleCode\ADONETSample
5. In the command prompt, enter one of the following commands to compile the sample (the
path to your file will likely differ).
6. For Visual Basic, use vbc.exe and use the following command to reference the system
libraries needed to run your ADO.NET application.
vbc.exe sample.vb /r: System.dll /r:System.Data.dll /r:System.Data.OracleClient.dll
/r:System.Xml.dll
8. List the .NET Framework data providers that are included in the .NET Framework?
(Nov 2018)
9. What are the Core elements of NET Framework data provider model.
The Connection, Command, DataReader, and DataAdapter objects represent the core
elements of the .NET Framework data provider model.
5Marks
10 Marks
1.EXPLAIN DIRECT ACCESS (or) .NET DATA PROVIDERS (or) CONNECTION
ENVIRONMENT (Nov 2018) (May-22)
Data providers act as a bridge between an application and database. It is used to retrieve data
from a database and send back to the database after changes.
Figure for Connection Environment
Connection Object:
These objects are used to create a connection to the database for moving data
between the database and user application.
The connection can be created using.
SQL Connection Object:
Open (), close (), and dispose () are the methods of connection object used to open
and close the defined connection.
Properties:
Select Command (Accessing Rows in a Database)
Insert Command (Inserting rows in the Database)
Update Command (For modifying rows in the Database)
Delete Command (For deleting rows)
FILL Method:
It is used to write the result of select command into the dataset.
Example:
Dim Myadapter As New SqlDataAdapter
Myadapter.select command = mycomm
Dim Mydataset As New Dataset ()
Myadapter.Fill (Mydataset, stud Table)
U20CSCM02 - C# AND .NET PRGRAMMING 9
SRI MANAKULA VINAYAGAR ENGINEERING COLLEGE Dept of CSE
conn.close ()
Sample C # Program for Connection Environment:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string connectionString = "Data Source=CENTRE-I-62;Initial
Catalog=management;Integrated Security=True";
string query1 = "select * from employee";
SqlConnection cn = new SqlConnection(connectionString);
cn.Open();
SqlCommand cmd1 = new SqlCommand(query1, cn);
SqlDataReader dr1 = cmd1.ExecuteReader();
while (dr1.Read())
{
Console.WriteLine(dr1[0] + " " + dr1[1] + " " + dr1[2] + " " + dr1[3] + " " + dr1[4]);
}
cn.Close();
Console.ReadLine();
}
}
}
Working of Datasets:
1. Create a connection object
Sql connection cn = New Sqlconnection ();
2. Set a connection String.
Cn.connection String = “Datasource = SQL Server36; Initial Catalog = HR; UserId =sa;
pwd =123”
3. Create an oject of the Dataset class
Dataset Dataset1 = new Dataset ()
4. Create an object of Sql Data Adapter class.
Sql Data Adapter da = New Sql Data Adapter ()
5. Pass the SQL Query to the Command object.
Sql command cmd = New Sql command (“Select * from Employee”, cn)
da.select command = cmd
6. Fill Datasets (ie) Fill the records into the Datasets.
Da.Fill (Dataset1);
r["salary"] = 20000;
ds.Tables["employee"].Rows.Add(r);
da.Update(ds, "employee");
Console.WriteLine("Updated");
cn.Close();
Console.ReadLine();
}
}}
PONDICHERRY UNIVERSITY QUESTIONS
2 MARKS
1. Define: Database. (NOV 2013)
2. What is the use of try block in VB.NET? (NOV 2013) (Ref.Qn.No.1, Pg.no.10)
3. What is the difference between copy() and clone()?(APRIL 2012)
4. Enumerate the distinct advantages of ADO.NET. (APR 2012) (Ref.Qn.No.11, Pg.no.5)
5. What are all the reason Exception can be raised? (NOV 2012)
6. List out the Exception Handling Model. (NOVEMBER 2012)
7. What is an Event? (APRIL 2013)
8. List the difference exists between command Text and Command Type. (APRIL 2013)
11 MARKS
1. Write a VB.NET program to sort the numbers using delegates. (NOVEMBER 2013)
2. Explain in detail about ADO.NET object model. (NOVEMBER 2013)
3. Write a program to add a new record in a database with following fields Student Id,
Student Name, Degree and Category. (APRIL 2012)
4. Explain in detail about the Object Model of the Dataset Class. (APRIL 2012)
5. Explain ADO.NET Object Model. (NOVEMBER 2012)
6. Discuss with Delegates. (NOVEMBER 2012)
7. Discuss about the properties of the connection class and command class. (APRIL 2013)
8. Explain delegates and events in detail. (APRIL 2013)