Home | Services | How To | Contact Us

www.HoustonianTECH.com

Home
Services
How To
Contact US

 
How to Connect to an SQLServer Database with ASP.NET - Using Stored Procedures

Session("conn") = ConfigurationManager.Appsettings("PathToDatabase")

'Setup Connection and Command Objects
Dim myConnection As New SqlConnection(Session("conn"))
Dim myCommand As New SqlCommand("StroedProcedureName", myConnection)
myCommand.CommandType = CommandType.StoredProcedure

'Setup Parameter Objects
Dim spParameter1 As New SqlParameter("@spParameter1", SqlDbType.VarChar, 50)
spParamter1.Value = Variable1
myCommand.Parameters.Add(spParameter1)
Dim spParameter2 As New SqlParameter("@spParameter2", SqlDbType.VarChar, 15)
spParameter2.Value = Variable1
myCommand.Parameters.Add(spParameter2)

'Open Connection
Try
myConnection.Open()

'Execute the Command
Dim SQL_Data As SqlDataReader
SQL_Data = myCommand.ExecuteReader()
SQL_Data.Read()

'Close the Connection
myConnection.Close()

Catch SQLexc As SqlException
Return False

End Try

Home | Services | How To | Contact Us
Login