Professional Documents
Culture Documents
What is ADO.NET?
ADO stands for Microsoft ActiveX Data Objects. ADO.NET is one of Microsoft’s Data Access technology using which we can communicate
with different data sources. It is a part of the .Net Framework which is used to establish a connection between the .NET Application and data
sources. The Data sources can be SQL Server, Oracle, MySQL, and XML, etc. ADO.NET consists of a set of classes that can be used to
connect, retrieve, insert, update and delete data (i.e. performing CRUD operation) from data sources. ADO.NET mainly
uses System.Data.dll and System.Xml.dll.
Now Use this Method to Create a New Connection to Data Source using the Server Explorer.
1. Click “Connect to Database” in the Server Explorer window (if its not visible, you can open it from the View menu, then click
Server Explorer.)
2. Follow these steps in the Data Link Properties dialog box:
a. In the Select or enter a server name text box, type localhost.
b. Under Enter information to log on to the server, ( if you need security click Use Windows NT
Integrated security).
3. Click Select the database on the server, and then select Database from the list of databases(eg Northwind ).
a. Click Test Connection to verify that the information is correct, and then click OK.
4. In the Server Explorer window, expand the Data Connections, the YourServerName.Northwind.dbo, and the Tables nodes.
5. Right-click Categories, and then click Retrieve Data from Table(this will fetch the Columns(Attributes) from the Database.
6. Edit one of the product descriptions, and then move to another record. Notice: These change affects the underlying data
source.
7. Right-click Categories, and then click Design Table. Change the length of the CategoryName column to 20(i.e size). Click
Save, and then verify the changes in the updated table.
8. Right-click Views, and then click New View. Add the Customers table to the view, and then click OK to close the Add Table
dialog box.
9. In the Customers table, select the following columns:CompanyNameContactNameContactTitle
10. Right-click in the SQL pane, and then click Verify SQL Syntax.
11. Right-click in the diagram pane, and then click Run.
12. Click Save, and then type CustomerInfo for the view.
Now to Display Data in a Windows Form
1. View yourForm in which you want to display Data in the Design window.
2. Drag the Categories node from the Server Explorer window to Form1 (yourForm), which adds the SqlConnection and the
SqlDataAdapter objects to the form. View the properties of these objects to verify that they are configured to connect to the
Categories table in the Northwind database.
3. Right-click SqlDataAdapter1, and then click Generate Dataset. Click OK in the Generate Dataset dialog box.
4. Add a DataGrid control to the form, and then set the DataSource property of the DataGrid to DataSet11.Categories.
5. Create an event handler for the Form_Load event, and then add the following code to this event:
1. SqlDataAdapter1.Fill(DataSet11)
Connection
You can connect your VB.Net application to data in a SQL Server database using the Microsoft .NET
Framework Data Provider for SQL Server. The first step in a VB.Net application is to create an instance of the
Server object and to establish its connection to an instance of SQL Server.
The SqlConnection Object is Handling the part of physical communication between the application and
the SQL Server Database. An instance of the SqlConnection class in .NET Framework is supported the Data
Provider for SQL Server Database. The SqlConnection instance takes Connection String as argument and pass
the value to the Constructor statement. When the connection is established , SQL Commands may be executed,
with the help of the Connection Object, to retrieve or manipulate data in the database. Once the Database
activities over , Connection should be closed and release the database resources .
User ID=UserName;Password=Password"
A Sample VB.Net Program that connect SQL Server using connection string.
Imports System.Data.SqlClient
Try
cnn.Open()
cnn.Close()
Catch ex As Exception
End Try
End Sub
End Class
Ole
Imports System.Data
Module Test
Sub Main()
Dim sConnectionString, sSQL As String
dr = cmd.ExecuteReader()
Do While dr.Read()
System.Console.WriteLine(dr.Item("Title"))
Loop
dr.Close()
conn.Close()
End Sub
End Module
What is command
The command object is used to execute select statements, insert, update, or delete
statements, stored procedures, or any other statement which is defined by database. ...
NET Framework Data Provider for SQL Server includes a SqlCommand object and oledb
includes an OleDbCommand object
SqlCommand Class
SqlCommand Properties
SqlCommand Method
What is DataAdapter ?
SqlDataAdapter sde = new SqlDataAdapter("Select * from student", con);
What is DataSet ?
Me.CUSTOMERSTableAdapter.Fill(Me.TestDBDataSet.CUSTOMERS)
' Set the caption bar text of the form.
Me.Text = "tutorialspoint.com"
End Sub
You can bind certain controls to the data control, the remote data control, and the ADO data
control, and those controls are called bound controls. To bind a control to a database control, you
use properties like DataSource to specify the database control, and then use properties
like DataField or BoundColumn to specify what field to display in the bound control, as we’ll
see. Here are the controls that can function as bound controls:
• Picture boxes
• Labels
• Text boxes
• Checkboxes
• Image controls
• OLE controls
• List boxes
• Masked edit controls
• Rich text boxes
• Combo boxes
In addition, there are special controls that are designed to be used as bound controls:
• DBList
• DBCombo
• FlexGrid
• MSFlexGrid
Finally, a number of bound controls are specially built to be used with the ADO control only:
• DataList
• DataCombo
• DataGrid