Continually Improving.... let us know how support@devdiamond.net Sign in | Sign up
home articles news blog forum  

 
 


 
Skip Navigation LinksHome > Article > Assigning Database information to Variables
Assigning Database information to Variables
Abstract :
In this article we will discuss how to assign database information to variables

Views : 7820
Published : Wednesday, February 04, 2004
By
HyperLink

Avarage Rating :
Page Page 1 of 3

We have this table called tblcustomers

ID Name Country City
23 Steve USA New York
24 Ahmed Egypt Cairo

What we want to do is to select customer with ID 24 and put his name "Ahmed" into a variable so that we can display it later

For this article i will use ASP.Net , Visual Basic .Net, and also demostrate the User Control technology on ASP.Net

Inti.vb


Imports System
Imports System.Data
Imports System.Data.OleDb
imports system.web.ui
imports system.web.ui.webControls

Namespace YasirNet

Public Class MyBasicClass
Inherits UserControl

'Here is my First Function in ASP.Net ConnectNow() which encapsulate the connection code

Public reader As OleDbDataReader
Public Function ConnectNow(strSQL AS String)
Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("/myfolder/mydatabase.mdb")

'Create an OleDbConnection object,
'and then pass in the ConnectionString to the constructor.
Dim cn As OleDbConnection = New OleDbConnection(connectString)

'Open the connection.
cn.Open()

'Use a variable to hold the SQL statement.
Dim selectString As String = strSQL

'Create an OleDbCommand object.
'Notice that this line passes in the SQL statement and the OleDbConnection object.
Dim cmd As OleDbCommand = New OleDbCommand(selectString, cn)

'Send the CommandText to the connection, and then build an OleDbDataReader.
'Note: The OleDbDataReader is forward-only.
reader = cmd.ExecuteReader()
End Function

End Namespace



About Author

        Yasir Send Feedback
        Yasir is a .NET expert, with over 5 years experience in Microsoft Technologies, 8 years overall programming experience, he is the owner, founder & primary contributor of Minwar.com, and he also works as IT Director in the hospitality industry.