Upendra Singh

Upendra Singh Page for personal images, blogs, gallery. Software Programmer at THINQ Pharma-CRO Ltd.

10/09/2021
31/03/2017
17/11/2015

Page for personal images, blogs, gallery.

15/11/2015

Interview Questions for DotNet Developers...
----------------------------------------------------------------------------
1) What is an internal modifier?
• Internal members can access only from within the same assembly (.dll).
• We can declare a class as internal, its member as internal or its fields as internal.
• Use internal keyword before the class declaration to create an internal class.
• Internal type can't access from external program.
• Classes defined within the current assembly can access internal classes.
2) What are namespaces, and how they are used?
• In .Net framework namespaces are used to manage classes.
• The Key difference between .Net namespaces and java packages is that namespace doesn’t define the physical layout of source file while java packages do.
• Namespace define logical structure of the code.
• Namespaces can be utilized via using keyword, in .net framework, many class have their namespace defined such as System.Net.
• We can create our own C # source files which can relate to multiple projects.
3) Why are strings in C # immutable?
• When string values changes it means string is immutable, in this whenever we assign new value to string it occupies new memory reference for its new value by creating new string instance.
• String is declared by using String Keyword.
• Always use mutable string defined in System.Text.StringBuilder whenever its values will change.
• Inefficient use of memory and garbage collection resulted by Immutable string.
4) What is boxing?
• When Value type is explicitly converted into reference type is called as boxing.
• The reverse process is known as unboxing, when reference type is explicitly converted into value type.
• In boxing process, the Values of variable is stored in Stack is converted in an object reference is stored in heap.
• If the recipient reference type is equivalent to the unboxed type, then the value is copied to the heap.
• Unboxing called the vice versa process of boxing.
5) How does C # differ from C++?
• C # doesn't support multiple inheritances while C++ does.
• We can use switch statement with string values in C # while in C++ only Character and integer values supported.
• Casting is Safer in C # than C++.
• C # doesn’t require semicolon on completion of class definition while C++ use.
• In C #, Command line parameter acts differently as compared to C++.
6) What is the difference between public, static and void?
• public: Public Modifier in C # is most liberal among all access modifiers, it can access from anywhere inside or outside other class. There is no access restriction in public modifiers .public keyword is used just before the class keyword to declare class as public.
• static: Static method is used to declare main method global one and we do not need to create instance of that class. We can access methods of static class by using the class name followed by. Operator and method name .The compiler stores Static method’s address and uses this information before any object is created for ex*****on.
• void: The void modifier tells that the Main method can't return any value.
7) What is shadowing?
There are two ways of shadowing either through scope or through inheritance.
• Hiding a method of child class and giving a new implementation is known as shadowing from inheritance.
• Shadowing through inheritance is the default when a derived class implements a method of base case which is not declared as overridden in the base class.
• Derived class member’s signature, return type, access level may differ from base class.
• Shadowing can be obtained by using the new keyword.
• Shadowing is one of the polymorphism’s concepts.
8) What are the difference between Structure and Class?
• Structures are Values types while Classes are Reference types.
• In structure values stored in stack while in class value’s reference stored in heap.
• In structure direct values is stored while in class reference to a value is stored.
• Inheritance is supported in classes while structure doesn’t support.
• We cannot declare destructor in structure whereas in class it is possible.
• We can’t have explicitly parameter less constructors in structure whereas classes can have.
• Class can have protected members while structure can’t have.
• Structure is declared by using struct keyword while class is declared by using Class keyword.
• Structures don’t have memory management while classes have due to garbage collector.
• New operator works in classes while not in structure.
9) How does assembly versioning work?
• There is an assembly’s version called the compatibility version.
• Version number is defined by four numeric parts (e.g. 5.5.3.11).
• Both the name and the version of the referenced assembly are included in each reference to an assembly.
• The two parts of assembly is normally seen as incompatible, but if third part is different than assemblies are deemed as ‘may be compatible’, and if the only fourth part of an assembly is different than assembly is compatible.
• We can specify version policy in the application configuration file.
• We cannot apply versioning to private assemblies; it is applied only to shared assemblies.
10) What is Custom Control?
• A Custom control inherits from System.Windows.Controls.Control class.
• They are compiled code (Dlls), faster to use, difficult to develop, and can be placed in toolbox.
• Custom controls can be derived from different custom controls according to requirement.
• Custom controls can be reused on multiple places easily.
• Provide more flexibility in extending the control’s behavior.
• Custom controls are loosely coupled control in respect to code an UI.
• Custom controls can be used just by drag and drop into the form.
• Custom controls have dynamic layout.
11) What is User Control?
• A User control inherits from System.Windows.Controls.UserControls class.
• User control defines UI as XMAL.
• User control has fixed UI and can’t have different look in every project.
• They are tightly coupled controls.
• We can’t add them to the toolbox.
• They are less flexible as compared to Custom controls.
12) How can I produce an assembly?
An assembly can produce from a .Net compiler.
For Example, the following C # program:
public class CDemo
{
public CDemo()
{
System.Console.WriteLine( "Hello from CDemo" );
}
}
Can be compiled into a dll as:
Csc/t:library cdemo.cs

Now the contents of assembly can be view through opening the “IL Disassembler” tool of .Net SDK.

Also compiling source into modules and then using assembly linker (al.exe) for combining them to generate assembly.
13) What is an application domain?
• An AppDomain is a lightweight activity.
• Goal of Appdomain is to isolate application from each other which is useful in hosting like Asp.net Application.
• The host can destroy the Appdomain without loosing others in the process.
• .Net runtime managed AppDomain memory to ensure that they don’t access other’s memory.
• AppDomain is useful in creation and destruction of types on the fly.
• AppDomain Created automatically on creation of new application by CLRHost.
14) What are the features of C #?
• C # is a powerful and simple programming language for writing applications.
• Developers can easily build the web services through any language, on any platform across the internet.
• C # is a hybrid of C++ and VB.
• C # has many C++ features in the area expressions, operators and statements.
• C # introduces improvement in boxing, unboxing, type safety, events, and versioning and garbage collections.
• It reduces programming error in the code due to fewer lines of code.
• C # has a key feature that can split up the implementation into logical pieces called region.
• It support multiline comment feature.
15) What is an abstract class?
• We can’t create the instance of an abstract class, because abstract classes are incomplete.
• Abstract modifier doesn’t supported by interface, Values type and static types.
• We can declare class as abstract by using abstract keyword in beggining of the class definition.
• Abstract class provides similar definition of base class which can be shared by multiple derived classes.
• Abstract class may define abstract methods by using the abstract keyword before the method definition.
• Abstract methods have no implementation, only they can be implemented in the derived class.

For Example:
public abstract class Demo
{
public abstract void DoWork(int a);
}
16) What is Managed code?
• Manage Code are the codes which require common language runtime for its ex*****on.
• Managed code target the services of the common language runtime in .Net framework.
• Managed code must provide the metadata necessary for the runtime to provide services like memory management, cross-language integration, code access security, and automatic lifetime control of objects.
• Managed code provides services like cross-language integration, code access security, memory management and automatic lifetime control of objects by supplying necessary metadata for runtime.
• Codes executed by Microsoft intermediate language are Managed code.
17) What is Un-Managed Code?
• Code which is perfectly executed by operating system is known as un-managed code.
• C, C++, VB 6.0 are examples of unmanaged code.
• Un-managed code all the time dependent on computer architecture.
• Un-managed code always compile to native code, so require compilation of code for different platform again and again.
• Developers should take care of type safety, security, memory allocations.
18) What is the difference between an event and a delegate?
• Events are the reason of happening and delegates are the address of function.
• In .Net, Delegates looks like an interface with a single method and you can make a call to it by delegate’s instance.
• By event’s you can let other people know that something going on.
• Events is declared by using “event” keyword whereas delegate is declared by using “delegate” keyword as below
Public event ;
Public delegates ;
• Adding a public multicast delegate field is same as adding a public event to a class.
19) How does .NET remoting work?
• .NET remoting is a process of sending messages through channels.
• Standard channels in remoting are HTTP and TCP.
• TCP is used for LANs only while HTTP can be used for LANs or WANs (internet).
• Support can provided for many message serialization formats. Examples are SOAP (XML-based) and binary.
• By default, the HTTP channel uses SOAP and the TCP channel uses binary. channela can use any serialization format.
• There are two styles of remote access:
1) SingleCall. Every request from a client is serviced by a new object. The object is thrown away on completion of request.
2) Singleton. Single server object processed all request from clients.
20) How do I spawn a thread?
We need to create an instance of a System.Threading.Thread object and passing it an instance of a ThreadStart delegate that will be executed on the new thread.

For example:

class MyDemoThread
{
public MyDemoThread( string initData )
{
m_data = initData;
m_thread = new Thread( new ThreadStart(ThreadMain) );
m_thread.Start();
} // ThreadMain() is executed on the new thread.
private void ThreadMain()
{
Console.WriteLine( m_data );
}
public void WaitUntilFinished()
{
m_thread.Join();
private Thread m_thread;
private string m_data;
}
In this case creating an instance of the MyDemoThread class is sufficient to spawn the thread and execute the MyDemoThread.ThreadMain() method:
MyDemoThread t = new MyDemoThread( "Hello, world." );
t.WaitUntilFinished();
21) What are partial classes?
• Derived classes focus more on important portions by splitting a class definition into multiple source files using partial classes.
• In partial class code is hidden in a file named Form.Designer.vb or Form.Designer.cs.
• Partial class files can be viewed by expending all files in solution explorer.
• We can enhance and extend auto-generated code by using partial classes.
• These multiple files get compiled into a single class during compilation.
22) What are attributes?
• Attributes describe a type, method, or property in a way that can be queried using a technique call reflection.
• Attributes specify which security privileges a class requires.
• Attributes provide a description, title, and copyright notice to explain an assembly.
• Attribute types derive from the System. Attribute base class and are declared using or [] notation.
• Visual studio automatically creates some standard attributes for your assembly when you create a project including title, description, company, guide and version.
• Attribute can also declare requirements or capabilities.
23) What are the File System Classes?
• The file system classes are separated into two types of classes: information and utility.
• Information classes derive from the FileSystemInfo base class.
• Information Classes exposes all the system information about file system objects like files, directories and drives and named as FileInfo and DirectoryInfo classes.
• DriveInfo class cannot derive from the FileSystemInfo class; it is an information class which represents a drive in the file system.
• The utility classes have static methods to perform function on file system objects such as file system paths and Directories.
• System.IO namespace contains collection of classes for files, drives and directories.
24) Switch statement works differently than in C++, why?
C # does not support an explicit fall through for case blocks.

The following code is not legal and will not compile in C # :

switch(a)
{
case 0: // some code here
case 1: // some code here
default: // some code here
break;
}

To run above code in C #, the code must be modified as shown below

class Demo
{
public static void Main()
{
int a = 3;
switch(a)
{
case 0: // do some code here
goto case 1;
case 1: // do some code here
goto default;
default: // do some code here
break;
}
}
}
25) Why Trim function is used in C #?
The Trim function is used to remove white spaces from the end and start of the instance.
Trim provide following methods as:
1) Trim(): This method of Trim is used to remove both off spaces from start and the end.
2) TrimStart(): This method of Trim is used to remove white spaces from the start of String.
3) TrimEnd(): This method of Trim is used to remove white spaces from the end of the string.

15/11/2015

Only for DotNet Developers...

Page for personal images, blogs, gallery.

15/11/2015

ADO.Net Connectivity in DotNet...

15/11/2015

Add a new Windows Form under the project and design it as following:

using System.Data.OleDb;
Declarations: OleDbConnection con; OleDbCommand cmd; OleDbDataReader dr;
Under Form Load: con=new OleDbConnection("Provider=Msdaora;User Id=Scott;Password=tiger");
cmd = new OleDbCommand("Select Deptno, Dname, Loc From Dept", con); con.Open(); dr = cmd.ExecuteReader();
label1.Text = dr.GetName(0); label2.Text = dr.GetName(1); label3.Text = dr.GetName(2); ShowData();
private void ShowData() {
if(dr.Read()) {
textBox1.Text = dr.GetValue(0).ToString(); textBox2.Text = dr[1].ToString(); textBox3.Text = dr["Loc"].ToString();
}
else { MessageBox.Show("Last record of the table."); }
}
Under Next Button: ShowData();
Under Close Button: if(con.State != ConnectionState.Closed) { con.Close(); } this.Close();
Working with Sql Server
Sql Server is a collection of databases, where a database is again collection of various objects like tables, views, procedures etc.; users of Sql Server can be owner of 1 or more databases at a time, so while connecting with sql server from a .net application within the connection string we need to specify name of the database we want to connect either by using Database or Initial Catalog attributes.

Sql Server provides 2 different modes of authentication for connecting with the DB Server those are: 1. Windows Authentication 2. Sql Server Authentication
When a user connects through windows authentication, Sql Server validates the account name and password using the windows principal token in the operating system; this means that the user identity is confirmed by windows, Sql Server does not ask for the password and does not perform the identity validation. When using Sql Server authentication, logins are created in sql server that is not based on windows user accounts, both the user name and password are created by using sql server and stored in sql server database. Users connecting with sql server authentication must provide their credentials every time they connect with DB Server.

Note: if we want to connect using windows authentication mode, within the connection string in the place of User Id and Password attributes use “Trusted_Connection=True” or “Integrated Security=SSPI” attributes.

Connecting String for Sql Server Authentication:
“Provider=SqlOledb;User Id=Sa;Password=;Database=[;Data Source=]”

Connecting String for Windows Authentication:
“Provider=SqlOledb;Trusted_Connection=True;Database=[;Data Source=]”
Or
“Provider=SqlOledb;Integrated Security=SSPI;Database=[;Data Source=]”
Creating a database on Sql Server:
Go to Start Menu -> Programs -> MS Sql Server -> Sql Server Management Studio, open it and provide the authentication details to login. Once the studio is opened in the LHS we find a window “Object Explorer”, in that right click on the node Databases, select “New Database” that opens a window asking for the name, enter the name as: , click ok which adds the database under databases node. Now expand the database node, right click on Tables node and select “New Table” which opens a window asking for column names and data types enter the following:
Eno (Int), Ename (Varchar), Job (Varchar), Salary (Money), Photo (Image), Status (Bit)
Now select Eno Column, right click on it and select the option “Set Primary Key” and make it as an identity or key column of the table. Select Status column, go to its properties in the bottom and set “Default value or Binding” property as 1, which takes the default value for status column as true. Click on the save button at top of the studio which will prompt for table name enter name as “Employee” and click Ok which adds the table under tables node. Now right click on the table created and select “Edit” which opens a window, in that enter the data we want ignoring Photo and Status columns. Close the studio.

Note: We can connect with Sql Server from .net applications either by using Oledb or SqlClient classes also. If using SqlConnection or OracleConnection classes to connect with databases then connection string doesn’t require Provider attribute to be specified as these classes are designed specific for those databases.
Add a new form in the project and design it as following:

using System.Data.SqlClient;
Declarations: SqlConnection con; SqlCommand cmd; SqlDataReader dr; string SqlStr;
Under Form Load: con = new SqlConnection("User Id=Sa;Password=;Database=;Data Source="); cmd = new SqlCommand(); cmd.Connection = con; con.Open(); LoadData();
private void LoadData() {
cmd.CommandText = "Select Eno, Ename, Job, Salary From Employee Order By Eno";
dr = cmd.ExecuteReader(); ShowData();
}
private void ShowData() {
if (dr.Read()) {
textBox1.Text = dr[0].ToString(); textBox2.Text = dr[1].ToString();
textBox3.Text = dr[2].ToString(); textBox4.Text = dr[3].ToString();
}
else { MessageBox.Show("No data exists."); }
}
Under Next Button: Show Data();
Under New Button:
textBox1.Text = textBox2.Text = textBox3.Text = textBox4.Text = "";
dr.Close(); cmd.CommandText = "Select IsNull(Max(Eno), 1000) + 1 From Employee";
textBox1.Text = cmd.ExecuteScalar().ToString(); btnInsert.Enabled = true; textBox2.Focus();
private void ExecuteDML() {
DialogResult d = MessageBox.Show(“Are you sure of executing the below Sql Statement?\n\n" + SqlStr,
"Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (d == DialogResult.Yes) {
cmd.CommandText = SqlStr; int count = cmd.ExecuteNonQuery();
if (count > 0) MessageBox.Show("Statement executed successfully");
else MessageBox.Show("Statement failed ex*****on");
LoadData();
} }
Under Insert Button:
SqlStr = "Insert Into Employee (Eno, Ename, Job, Salary) Values(" + textBox1.Text + ", '" + textBox2.Text + "', '" + textBox3.Text + "', " + textBox4.Text + ")"; ExecuteDML(); btnInsert.Enabled = false;
or
SqlStr = String.Format("Insert Into Employee (Eno, Ename, Job, Salary) Values({0}, '{1}', '{2}', {3})", textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text); ExecuteDML(); btnInsert.Enabled = false;
Under Update Button:
SqlStr = "Update Employee Set Ename='" + textBox2.Text + "', Job='" + textBox3.Text + "', Salary=" + textBox4.Text + " Where Eno=" + textBox1.Text; dr.Close(); ExecuteDML(); or
SqlStr = String.Format("Update Employee Set Ename='{0}', Job='{1}', Salary={2} Where Eno={3}", textBox2.Text, textBox3.Text, textBox4.Text, textBox1.Text); dr.Close(); ExecuteDML();
Under Delete Button:
SqlStr = "Delete From Employee Where Eno=" + textBox1.Text; dr.Close(); ExecuteDML(); or
SqlStr = String.Format("Delete From Employee Where Eno={0}", textBox1.Text); dr.Close(); ExecuteDML();
Under Close Button: if (con.State != ConnectionState.Closed) { con.Close(); } this.Close();
DataReader: it's a class designed for holding the data on client machines in the form of Rows and Columns.

Features of DataReader:
1. Faster access to data from the data source as it is connection oriented.
2. Can hold multiple tables in it at a time. To load multiple tables into a DataReader pass multiple select statements as arguments to command separated by a semi-colon.
E.g.: Command cmd = new Command("Select * From Student;Select * From Teacher", con);
DataReader dr = cmd.ExecuteReader();

Note: use NextResult() method on data reader object to navigate from current table to next table.
E.g.: dr.NextResult();

Drawbacks of DataReader:
1. As it is connection oriented requires a continuous connection with data source while we are accessing the data, so there are chances of performance degradation if there are more no. of clients accessing data at the same time.
2. It gives forward only access to the data i.e. allows going either to next record or table but not to previous record or table.
3. It is a read only object which will not allow any changes to data that is present in it.

Dis-Connected Architecture: ADO.Net supports 2 different models for accessing data from Data Sources:
1. Connection Oriented Architecture 2. Disconnected Architecture
In the first case we require a continuous connection with the data source for accessing data from it, in this case we use DataReader class for holding the data on client machines, where as in the 2nd case we don’t require a continuous connection with data source for accessing of the data from it, we require the connection only for loading the data from data source and here DataSet class is used for holding the data on client machines.
Working with DataSet
DataSet: It's a class present under System.Data namespace designed for holding and managing of the data on client machines apart from DataReader. DataSet class provides the following features:
1. It is designed in disconnected architecture which doesn't require any permanent connection with the data source for holding of data.
2. It provides scrollable navigation to data which allows us to move in any direction i.e. either top to bottom or bottom to top.
3. It is updatable i.e. changes can be made to data present in it and those changes can be sent back to DB.
4. DataSet is also capable of holding multiple tables in it.
5. It provides options for searching and sorting of data that is present under it.
6. It provides options for establishing relations between the tables that are present under it.
Using DataSet's: The class which is responsible for loading data into DataReader from a DataSource is Command, in the same way DataAdapter class is used for communication between DataSource and DataSet.

DataReader DataSource
DataSet DataAdapter DataSource

Constructors of DataAdapter class:
DataAdapter(string selectcommand, Connection con) DataAdapter(Command cmd)
Note: selectcommand means it can be a select statement or a Stored Procedure which contains a select statement.

Methods of DataAdapter:
Fill(DataSet ds, string tableName) Update(DataSet ds, string tableName)

DataAdapter’s can internally contain 4 Commands under them associated with a single table, those are:
-Select Command -Insert Command -Update Command -Delete Command

When we call Fill method on DataAdapter following actions takes place internally:
• Opens a connection with the Data Source.
• Executes the SelectCommand present under it on the DataSource and loads data from table to DataSet.
• Closes the connection.

As we are discussing DataSet is updatable, we can make changes to the data that is loaded into it like adding, modifying and deleting of records, after making changes to data in DataSet if we want to send those changes back to DataSource we need to call Update method on DataAdapter, which performs the following:
• Re-opens a connection with the Data Source.
• Changes that are made to data in DataSet will be sent back to corresponding table, where in this process it will make use of Insert, Update and Delete commands of DataAdapter.
• Closes the connection.

Accessing data from DataSet: Data Reader’s provides pointer based access to the data, so we can get data only in a sequential order whereas DataSet provides index based access to the data, so we can get data from any location randomly. DataSet is a collection of tables where each table is represented as a class DataTable and identified by its index position or name. Every DataTable is again collection of Rows and collection of Columns where each row is represented as a class DataRow and identified by its index position and each column is represented as a class DataColumn and identified by its index position or name.

• Accessing a DataTable from DataSet: .Tables[index] or .Tables[name]
E.g.: ds.Tables[0] or ds.Tables["Employee"]
• Accessing a DataRow from DataTable: .Rows[index]
E.g.: ds.Tables[0].Rows[0]
• Accessing a DataColumn from DataTable: .Columns[index] or .Columns[name]
E.g.: ds.Tables[0].Columns[0] or ds.Tables[0].Columns["Eno"]
• Accessing a Cell from DataTable: .Rows[row][col]
E.g.: ds.Tables[0].Rows[0][0] or ds.Tables[0].Rows[0]["Eno"]
Add a new form in the project, design it as below, then add reference of Microsoft.VisualBasic assembly from Framework tab of add reference window and write the code:

using System.Data.SqlClient; using Microsoft.VisualBasic;
Declarations: SqlConnection con; SqlDataAdapter da; sqlCommandBuilder cb; DataSet ds; int rno = 0;
Under Form Load:
con = new SqlConnection("User Id=Sa;Password=;Database=;Data Source=");
da = new SqlDataAdapter("Select Eno, Ename, Job, Salary From Employee Order By Eno", con);
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
ds = new DataSet(); da.Fill(ds, "Employee"); ShowData();

15/11/2015

ADO.Net
Pretty much every application deals with data in some manner, whether that data comes from memory, databases, XML files, text files, or something else. The location where we store the data can be called as a Data Source or Data Store where a Data Source can be a file, database, or indexing server etc.

Programming Languages cannot communicate with Data Sources directly because each Data Source adopts a different Protocol (set of rules) for communication, so to overcome this problem long back Microsoft has introduced intermediate technologies like JET, Odbc and Oledb which works like bridge between the Applications and Data Sources to communicate with each other.

The Microsoft Jet Database Engine is a database engine on which several Microsoft products have been built. A database engine is the underlying component of a database, a collection of information stored on a computer in a systematic way. The first version of Jet was developed in 1992, consisting of three modules which could be used to manipulate a database. JET stands for Joint Engine Technology, sometimes being referred to as Microsoft JET Engine or simply Jet. Microsoft Access and Excel uses Jet as their underlying database engine. Over the years, Jet has become almost synonymous with Microsoft Access, to the extent where many people refer to a Jet database as an "Access database". MS developed Jet database system, a C-based interface allowing applications to access that data, and a selection of driver DLLs that allowed the same C interface to redirect input and output to databases. However, Jet did not use SQL; the interface was in C and consisted of data structures and function calls.

ODBC (Open Database Connectivity) is a standard C programming language middleware API for accessing database management systems (DBMS). ODBC accomplishes DBMS independence by using an ODBC driver as a translation layer between the application and the DBMS. The application uses ODBC functions through an ODBC driver manager with which it is linked, and the driver passes the query to the DBMS. An ODBC driver will be providing a standard set of functions for the application to use, and implementing DBMS-specific functionality. An application that can use ODBC is referred to as "ODBC-compliant". Any ODBC-compliant application can access any DBMS for which a driver is installed. Drivers exist for all major DBMSs as well as for many other data sources like Microsoft Excel, and even for text or CSV files. ODBC was originally developed by Microsoft during the early 1990s.

OLE DB (Object Linking and Embedding, Database, sometimes written as OLEDB or OLE-DB), an API designed by Microsoft, allows accessing data from a variety of sources in a uniform manner. The API provides a set of interfaces implemented using the Component Object Model (COM). Microsoft originally intended OLE DB as a higher-level replacement for, and successor to, ODBC, extending its feature set to support a wider variety of non-relational databases, such as object databases and spreadsheets that do not necessarily implement SQL. OLE DB is conceptually divided into consumers and providers. The consumers are the applications that need access to the data, and the providers are the software components that implement the interface and thereby provide the data to the consumer. An OLE DB provider is a software component enabling an OLE DB consumer to interact with a data source. OLE DB providers are alike to ODBC drivers or JDBC drivers for Java. OLE DB providers can be created to access such simple data stores as a text file and spreadsheet, through to such complex databases as Oracle, Microsoft SQL Server, and many others. It can also provide access to hierarchical data stores.

DAO’s, RDO’s and ADO’s in Visual Basic Language:
Visual Basic Language used DAO’s, RDO’s and ADO’s for data source communication without having to deal with the comparatively complex JET or ODBC or OLEDB API.

Data Access Objects is a deprecated general programming interface for database access on Microsoft Windows systems using Joint Engine Technology.

Remote Data Objects (abbreviated RDO) is the name of an obsolete data access application programming interface primarily used in Microsoft Visual Basic applications on Windows 95 and later operating systems. This includes database connection, queries, stored procedures, result manipulation, and change commits. It allowed developers to create interfaces that can directly interact with Open Database Connectivity (ODBC) data sources on remote machines.

Microsoft's ActiveX Data Objects (ADO) is a set of Component Object Model (COM) objects for accessing data sources. It provides a middleware layer between programming languages and OLE DB (a means of accessing data stores, whether they be databases or otherwise, in a uniform manner). ADO allows a developer to write programs that access data without knowing how the database is implemented; developers must be aware of the database for connection only. ADO is positioned as a successor to Microsoft's earlier object layers for accessing data sources, including RDO (Remote Data Objects) and DAO (Data Access Objects). ADO was introduced by Microsoft in October 1996.
ADO.NET Providers:
ADO.NET providers can be created to access such simple data stores as a text file and spreadsheet, through to such complex databases as Oracle, Microsoft SQL Server, MySQL, PostgreSQL, SQLite, DB2, Sybase ASE, and many others. They can also provide access to hierarchical data stores such as email systems. However, because different data store technologies can have different capabilities, every ADO.NET provider cannot implement every possible interface available in the ADO.NET standard.

ADO.Net:
It is a set of classes that expose data access services to the .NET programmer. ADO.NET provides functionality to developers writing managed code similar to the functionality provided to native COM developers by ADO. ADO.NET provides consistent access to data sources such as Microsoft SQL Server, as well as data sources exposed through OLE DB and XML. Data-sharing consumer applications can use ADO.NET to connect to these data sources and retrieve, manipulate, and update data. 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 or Internet browsers. ADO.Net provides libraries for Data Source communication under the following namespaces:
• System.Data
• System.Data.Odbc
• System.Data.Oledb
• System.Data.SqlClient
• System.Data.OracleClient

Note: System.Data, System.Data.Oledb, System.Data.SqlClient and System.Data.Odbc namespaces are under the assembly System.Data.dll whereas System.Data.OracleClient is under System.Data.OracleClient.dll assembly.

System.Data: types of this namespace are used for holding and managing of data on client machines. This namespace contains following set of classes in it: DataSet, DataTable, DataRow, DataColumn, DataView, DataRelation etc.
System.Data.Odbc: types of this namespace can communicate with any Data Source like files, databases, and indexing servers etc. using Un-Managed Odbc Drivers.
System.Data.Oledb: types of this namespace can communicate with any Data Source like files, databases, and indexing servers etc. using Oledb Providers (Un-Managed COM Providers).
System.Data.SqlClient: types of this namespace can purely communicate with Sql Server database only using SqlClient Provider (Managed ADO.Net Provider).
System.Data.OracleClient: types of this namespace can purely communicate with Oracle database only using OracleClient Provider (Managed ADO.Net Provider).

All the above 4 namespaces contains same set of types as following: Connection, Command, DataReader, DataAdapter, CommandBuilder etc, but here each class is referred by prefixing with their namespace before the class name to discriminate between each other as following:

OledbConnection OledbCommand OledbDataReader OledbDataAdapter OledbCommandBuilder
SqlConnection SqlCommand SqlDataReader SqlDataAdapter SqlCommandBuilder
OracleConnection OracleCommand OracleDataReader OracleDataAdapter OracleCommandBuilder
OdbcConnection OdbcCommand OdbcDataReader OdbcDataAdapter OdbcCommandBuilder
Performing Operations on a DataSource: Each and every operation we perform on a Data Source involves in 3 steps, like:
• Establishing a connection with data source.
• Sending request to data source as a sql statement.
• Capturing the results given by data source.

Establishing a Connection with Data Source:
It's a process of opening a channel for communication between Application and Data Source that is present on a local or remote machine to perform any operations. To open the channel for communication we can use the Connection class.

Constructors of the Class:
Connection() Connection(string ConnectionString)

Note: ConnectionString is a collection of attributes that are used for connecting with a DataSource, those are:
• Provider
• Data Source
• User Id and Password
• Database or Initial Catalog
• Trusted_Connection or Integrated Security
• DSN
Provider: as discussed earlier provider is required for connecting with any data source, so we have a different provider available for each data source.
Oracle Msdaora Sql Server SqlOledb
MS-Access or MS-Excel Microsoft.Jet.Oledb.4.0 MS-Indexing Server Msidxs
Data Source: it is the name of target machine to which we want to connect with but it is optional when the data source is on a local machine.
User Id and Password: as db's are secured places for storing data, to connect with them we require a valid user id and password.
Oracle: Scott/tiger Sql Server: Sa/
Database or Initial Catalog: these attributes are used while connecting with Sql Server Database to specify the name of database we want to connect with.
Trusted_Connection or Integrated Security: these attributes are also used while connecting with Sql Server Database only to specify that we want to connect with the Server using Windows Authentication. In this case we should not again use User Id and Password attributes.
DSN: this attribute is used to connect with data sources by using Odbc Drivers.

Connection String for Oracle: "Provider=Msdaora;User Id=Scott;Password=tiger[;Data Source=]"

Connection String for Sql Server: "Provider=SqlOledb;User Id=Sa;Password=;Database=[;Data Source=]"

Note: in case of Windows Authentication in place of User Id and Password attributes we need to use Integrated Security = SSPI (Security Support Provider Interface) or Trusted_Connection = True.
Members of Connection class:
1. Open(): a method which opens a connection with data source.
2. Close(): a method which closes the connection that is open.
3. State: an enumerated property which is used to get the status of connection.
4. ConnectionString: a property with is used to get or set a connection string which is associated with the connection object.
The Object of class Connection can be created in any of the following ways:
Connnection con = new Connection(); con.ConnectionString = "";
or
Connection con = new Connection("");
Testing the process of establishing a connection: open a new project of type Windows Forms Application and name it as DBOperations. Place 2 buttons on the form and set their caption as “Connect with Oracle using OLEDB Provider” and “Connect with Sql Server using OLEDB Provider”. Now go to code view and write the following code:
using System.Data.OleDb;
Declarations: OledbConnection ocon, scon;
Under Connect with Oracle using OLEDB Provider:
ocon = new OleDbConnection(“Provider=Msdaora;User Id=Scott;Password=tiger;Data Source=");
ocon.Open(); MessageBox.Show(ocon.State.ToString()); ocon.Close(); MessageBox.Show(ocon.State.ToString());
Under Connect with Sql Server using Oledb Provider:
scon = new OleDbConnection(); scon.ConnectionString =
"Provider=SqlOledb;User Id=Sa;Password=;Database=Master;Data Source=";
scon.Open(); MessageBox.Show(scon.State.ToString()); scon.Close(); MessageBox.Show(scon.State.ToString());
Sending request to Data Source as a Sql Statement: In this process we send a request to Data Source by specifying the type of action we want to perform using a Sql Statement like Select, Insert, Update, and Delete or by calling a Stored Procedure. To send and execute those statements on data source we use the class Command.

Constructors of the class: Command() Command(string CommandText, Connection con)
Note: CommandText means it can be any Sql Stmt like Select or Insert or Update or Delete Stmts or Stored Procedure Name.

Properties of Command Class:
1. Connection: sets or gets the connection object associated with command object.
2. CommandText: sets or gets the sql statement or SP name associated with command object.

The object of class Command can be created in any of the following ways:
Command cmd = new Command(); cmd.Connection = ; cmd.CommandText = "";
or
Command cmd = new Command("", con);

Methods of Command class:
• ExecuteReader() -> DataReader
• ExecuteScalar() -> object
• ExecuteNonQuery() -> int
Note: after creating object of Command class we need to call any of these 3 methods to execute that statement.

Use ExecuteReader() method when we want to execute a Select Statement that returns data as rows and columns. The method returns an object of class DataReader which holds data that is retrieved from data source in the form of rows and columns.
Use ExecuteScalar() method when we want to execute a Select Statement that returns a single value result. The method returns result of the query in the form of an object.
Use ExecuteNonQuery() method when we want to execute any SQL statement other than select, like Insert or Update or Delete etc. The method returns an integer that tells the no. of rows affected by the statement.
Note: The above process of calling a suitable method to capture the results is our third step i.e. capturing the results given by data source.
Accessing data from a DataReader: DataReader is a class which can hold data in the form of rows and columns, to access data from DataReader it provides the following methods:

1. GetName(int columnindex) -> string
Returns name of the column for given index position.
2. Read() -> bool
Moves record pointer from the current location to next row and returns a bool value which tells whether the row to which we have moved contains data in it or not, that will be true if data is present or false if data is not present.
3. GetValue(int coloumnindex) -> object
Used for retrieving column values from the row to which pointer was pointing by specifying the column index position. We can also access the row pointed by pointer in the form of a single dimensional array also, either by specifying column index position or name, as following:
[column index] -> object
[column name] -> object

Address

Puranik City
Thane
401107

Alerts

Be the first to know and let us send you an email when Upendra Singh posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.

Contact The Business

Send a message to Upendra Singh:

Share