Need Help with Database Connection w/ ASP.NET!

  • Thread starter Sparky Arbuckle
  • Start date
S

Sparky Arbuckle

web.config

<?xml version="1.0" encoding="utf-8" ?>

<configuration>
<!-- application specific settings -->

<appSettings>
<add key="myConnection" value="Provider=Microsoft.Jet.OLEDB.4.0;Data
source=Customers.mdb;" />
</appSettings>

<system.web>
<httpRuntime executionTimeout="5" maxRequestLength="8192"/>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>

</configuration>
--------------------------------------------------------

DataGridEmail.aspx (Connection String)

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<SCRIPT runat="SERVER">

'Modified from Payne Listings 10.10 & 10.11
'declare connection object with page-level scope (use in two
subroutines)

Dim myConnection as NEW
OLEDBConnection(ConfigurationSettings.AppSettings("Customers"))

Sub Page_Load(obj as Object, e as EventArgs)
IF NOT Page.IsPostBack then subFillDataGrid()
END Sub

Sub subFillDataGrid(Optional EditIndex as integer=-1)
'If Datagrid is in edit mode then specify row to edit
IF NOT EditIndex.Equals(Nothing) then dgData.EditItemIndex = EditIndex

'Initialize command object
Dim objCommand as new OleDbCommand ("SELECT CustID, FirstName,
LastName, Email", myConnection)

TRY
myConnection.Open()
dgData.DataSource =
objCommand.ExecuteReader(CommandBehavior.CloseConnection)
dgData.DataBind()
CATCH objError as Exception
lblMessage.text += "<br />FillDataGrid "
lblMessage.text += "<br />Error message - " & objError.Message
lblMessage.text += "<br />Error source - " & objError.Source
END TRY

END Sub
--------------------------------------------

My error is as follows:

Error message - The ConnectionString property has not been initialized.
Error source - System.Data

Any help would be greatly appreciated!
 
G

Guest

Hi, I think this should help :)

Dim myConnection as NEW
OLEDBConnection(ConfigurationSettings.AppSettings("myConnection"))

Your key for the connection string in <appSettings> is "myConnection" NOT
"Customers"
 
C

Chris Botha

From your example your setting in <appSettings> is called "myConnection" and
in the code you use "ConfigurationSettings.AppSettings("Customers")".
It may be good to debug it in steps, put a break and ensure you get the
right value from AppSettings. After that stick it into the connection string
and debug further.
 
S

Sparky Arbuckle

Error message - No value given for one or more required parameters.
Error source - Microsoft JET Database Engine

I have no idea what is going on here. I can tell that something is
starting to work.

Thanks everyone for the prompt replies!
 
S

Sparky Arbuckle

LOFL!

I selected from the database originally:

Dim objCommand as NEW OLEDBCommand ("SELECT CustID, FirstName,
LastName, Email", myConnection)

I forgot to add FROM tblCustomers

Oh man, I love ASP.NET debugging. It was ready to SELECT but had no
idea where to SELECT FROM!

Thanks everyone. Since everyone is so helpful I will probably be back!
 
S

Sparky Arbuckle

Now I run into another problem when I go to add a customer to the
database.

Number of query values and destination fields are not the same. -->
Error message that I get.

My code is as follows:

Sub Insert_onclick(obj as object, e as eventargs)
'insert new data
Dim strText as string
Dim strSQL as string = "INSERT INTO tblCustomers " & _
"(CustID, FirstName, LastName, Email) VALUES (" & _
"'" & CleanData(tbFName.text) & "'," & _
"'" & CleanData(tbLName.text) & "')" & _
"'" & CleanData(tbEmail.text) & "')"

tbFName.text = ""
tbLName.text = ""
tbEmail.text = ""

ExecuteSQL(strSQL)
subFillDataGrid()
END Sub
 
S

Sparky Arbuckle

Nevermind. I got it. It seems that the Error Debugging script is
pretty worthless. I was missing a parentheses! Damn you ASP.NET!
 

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

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top