Database connections in a code behind file.

D

Des

I am trying to connect to SQL Server. I have written some pages that
have got the line
Dim strConn as String = ConfigurationSettings.AppSettings("Thermos")
There is a valid line
<add key="Thermos" value="server=(local)\NetSDK; database=Thermos;
integrated security=true;" />

In web.config This is working fine. What I want to do is move some of
the code into a code behind file
Functions.vb. This is where things are going wrong. The following is
included in the Functions.vb file

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient
Imports System.DateTime

Public Class Functions : Inherits Page

But the line(s)


Dim strConn as String = ConfigurationSettings.AppSettings("Thermos")
Dim Adapter as new SqlDataAdapter(strItem,objConn)

As well as others are not recognized. Can this be achieved in a code
behind file

What I want out of my aspx file is

......
int = AddtoBasket(int ,int, int)
int = AddCustomer(char ,int, date) etc.
 
G

Guest

Should be because you haven't imported the namespace. Use:
Imports System.Configuration
 
D

Des

Thanks for that but now ir doesn't like Dim Adapter as new
SqlDataAdapter()

sqlProduct = "SELECT Name , Cost FROM Products WHERE ProductID = "
& ProdID
Dim Adapter as new SqlDataAdapter(strItem,objConn)


I have the esential inports

Imports System.Data
Imports System.Data.SqlClient
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top