473,414 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Outside function OleDbConnection Conn = new OleDbConnection

Hi all.

I'm really sorry for this post, I'm sure most of you will think it's a
silly question, but the following doesn't work and I'm really new to
ASP.NET:

<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
OleDbConnection Conn = new OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+
Server.MapPath("/tyaspnet21days") +"\\banking1.mdb");

void Page_Load(Object Sender, EventArgs e) {
if (!Page.IsPostBack) {
FillDataGrid();
}
}

CS0118: 'System.Web.UI.Page.Server' denotes a 'property' where a
'class' was expected

I get a compilation error on line 5 "OleDbConnection Conn = new
OleDbConnection"

It doesn't work and I know it will not work that way, but what is the
reason?
In VB.net I can use:

dim Conn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source="& Server.MapPath("/tyaspnet21days") &"\banking1.mdb")

I got the code from Teach Yourself ASP.NET in 21 days, I would also
like to add that none of the examples work.

If I place the connection in "void Page_Load(Object Sender, EventArgs
e) {" it works, but then I get errors from functions trying to use
that connection....

CS0103: The name 'Conn' does not exist in the class or namespace
'ASP.Project_aspx'

Thank you.
Nov 15 '05 #1
1 7209
I% SAY :::
does it work if you put it all on the same line

OleDbConnection Conn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+ Server.MapPath("/tyaspnet21days") +"\\banking1.mdb");

does it work if you do

OleDbConnection Conn = new OleDbConnection();

and set the properties later, individually ?

Hi all.

I'm really sorry for this post, I'm sure most of you will think it's a
silly question, but the following doesn't work and I'm really new to
ASP.NET:

<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
OleDbConnection Conn = new OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+
Server.MapPath("/tyaspnet21days") +"\\banking1.mdb");

void Page_Load(Object Sender, EventArgs e) {
if (!Page.IsPostBack) {
FillDataGrid();
}
}

CS0118: 'System.Web.UI.Page.Server' denotes a 'property' where a
'class' was expected

I get a compilation error on line 5 "OleDbConnection Conn = new
OleDbConnection"

It doesn't work and I know it will not work that way, but what is the
reason?
In VB.net I can use:

dim Conn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source="& Server.MapPath("/tyaspnet21days") &"\banking1.mdb")

I got the code from Teach Yourself ASP.NET in 21 days, I would also
like to add that none of the examples work.

If I place the connection in "void Page_Load(Object Sender, EventArgs
e) {" it works, but then I get errors from functions trying to use
that connection....

CS0103: The name 'Conn' does not exist in the class or namespace
'ASP.Project_aspx'

Thank you.


Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ecowalker | last post by:
Hello, I've try the following code in the ASPX and it throw a Security Exception in the runtime, but I've try to run on my colleagues machine without any problem. I am using XP Pro and IIS5.1...
0
by: Ray | last post by:
Hi All I've tried to read a .csv file and bind the data to a datagrid. I am doing sth like this: conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"+ "Data Source=" + csvPath + ";"...
1
by: Souloron | last post by:
Here what I did: string cmdText = String.Format(("CREATE TABLE {0} (dno int primary key, Sunday char(5), Monday char(5), Tuesday char(5), Wednesday char(5), Thursday char(5),...
1
by: Sabine25 | last post by:
Hello, It's the first time that I program in C# with Visual Studio and I've got a problem, I would like to know where is my error! This is my code: OleDbConnection conn = null; ...
4
by: tamarindm | last post by:
I am using the following to connect to a Sybase server. OleDbConnection Conn= new OleDbConnection(); string connstr = "Provider=Sybase ASE OLE DB Provider;Data Source=SERVER;User...
9
by: Justin Voelker | last post by:
I have a configuration file that contains the host, username, password, and database name required for any database connections. The config file runs through a few if/then/else statements to...
2
by: user | last post by:
Hi everyone, Im using the following conn string in asp.net 1.1 using vb.net: Dim conn As New OleDbConnection("Provider=MS Remote;Remote Server=http://myintranetserver/; Remote...
2
by: dotnetnovice | last post by:
Hi everybody! I have a problem and need help Here is the code. public void GetAllValues(Person V) { SqlConnection conn = new SqlConnection(ConnectionString); ...
3
by: DaveRook | last post by:
Hello Let me show you the code I'm trying to do and then I'll ask the question: SqlDataReader rdr = null; SqlConnection conn = new SqlConnection(strConn); string strSQL = "SELECT * FROM...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.