There
is many ways to implement a data layer class with .NET. This a simple
example demonstrate how to build a dataset against an SQL Server.
By Marc-Andre Heroux
Imports System.Data
Imports System.Data.SqlClient
Public Class DataLayer
Inherits System.Web.UI.Page
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
#Region " Web Form Designer
Generated Code "
'This call is required by
the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal
sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal
sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Call loadData("REMOTE\SQLSERVER", "sqlnet", "Password",
"books1")
End Sub
Public Function loadData(ByVal Server, ByVal User, ByVal pass, ByVal database)
Dim DBconn As New SqlConnection("server=" & Server &
";" & "UID=" & User & ";" &
"PWD=" & pass & ";" & "database="
& database)
DBconn.Open()
Dim sqladpt As New SqlDataAdapter("SELECT title from books1_desc",
DBconn)
Dim mydataset As New DataSet("books1")
sqladpt.Fill(mydataset)
DropDownList1.DataSource = mydataset
DropDownList1.DataTextField = "title"
DropDownList1.DataBind()
DBconn.Dispose()
DropDownList1.Enabled = True
End Function
End Class
For more information
on Data Layering with .NET, you can contact Marc-Andre at: maheroux@tcpcom.net
|
| 
Marc-Andre Heroux, CISSP, CISA, CGEIT, NSA Cert. is an information system specialist. Working
with technologies since 1990, his favorites programming languages
are C, Pearl, JAVA, JavaScript, PHP and .NET.
|
|