Access database at runtime using ADO.NET

Access database at runtime using ADO.NET

Steps to connect to database:

- Declare and initialize database connection object with appropriate connection string.
- Create a DataAdapter and a Dataset object.
- Using fill method of the DataAdapter object, load the data into the Dataset Object.
- Display the data using data binding feature of controls like Datagrid or Datalist.

Code to connect to database using VB.NET
Dim m_adptEmp As SqlDataAdapter

Private Sub Page_Load(ByVal sender As System.Object, _ByValeAsSystem.EventArgs) HandlesMyBase.Load<BR> DimEmpConnAsNewSqlConnection_<BR> ("server=(local);database=Employees;Trusted_Connection=yes")
     m_adptEmp = New SqlDataAdapter("select * from Emp", EmpConn)
     Dim dsEmp As New DataSet
     m_adptEmp.Fill(dsEmp, "Emp")
     DataGrid1.DataSource = dsEmp.Tables("Emp").DefaultView
     DataGrid1.DataBind()
End Sub
ADO.NET Code showing Dataset storing multiple tables
ADO.NET Code showing Dataset storing multiple tables - Declare and initialize database connection object with appropriate connection string.....
ADO.NET Code executing stored procedure
ADO.NET Code executing stored procedure - Code showing how to fetch data using Stored Procedure...
ADO.NET transaction Processing
ADO.NET transaction Processing - The transaction object handles concurrency issue using IsolationLevel settings. The settings can be....
Post your comment