Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 12th, 2004, 03:29 PM
Authorized User
 
Join Date: Oct 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default denotes a 'field' where a 'class' was expected

Hi all,

I have a little problem with the connection object. when I compile, it gave me error:

...CustomerManager.connection' denotes a 'field' where a 'class' was expected


I have no ideal why. I shoud be able to have a SqlConnection object as a field in CustomerManager class right? How can I fix this?

Thanks

John


1) I have ConnectionManager class have 1 public method that return an opened SqlConnection object

public class ConnectionManager {

   public static SqlConnection getConnection() {

   SqlConnection connection = new SqlConnection (SQL_CONNECTION_STRING_POOL);
connection.Open();
return connection;

}
}

2. I have another class call CustomerManager that have some methods
in this case , I just show 1 method: addCustomer.

public class CustomerManager {

SqlConnection connection = ConnectionManager.getConnection();

public static bool addCustomer(Customer cust) {

   // codes here
   //
   //
  line 100 SqlCommand command = new SqlCommand(sql, connection);

   // code here

}

}

 
Old November 12th, 2004, 03:39 PM
Authorized User
 
Join Date: Oct 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I see the problem since the addCustomer(customer in) is static then the connection field will not be initialized.

John






Similar Threads
Thread Thread Starter Forum Replies Last Post
Main.java:88: 'class' or 'interface' expected samnachilomo Java Basics 1 December 13th, 2006 09:07 AM
Property access from Class within Partial Class zoltac007 C# 2005 0 December 1st, 2006 01:01 AM
static field with class instance prakash.suthar Java Basics 2 July 3rd, 2006 01:41 AM
Regarding Class Library (.dll) from class file manish.sharma04 BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 March 3rd, 2006 07:32 AM
How to include c# class and vb class in the .vbprj umeshayk VS.NET 2002/2003 2 January 9th, 2004 12:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.