5 Replies - 2096 Views - Last Post: 03 April 2013 - 08:56 AM Rate Topic: -----

#1 khull1989  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 19-May 09

Expected class, delegate, enum, interface, or struct

Posted 01 April 2013 - 04:44 PM

Hello all,


I am making a web page that gathers information from text boxes and some other controls, and I am having a hard time getting the data source to capture the information and add it to the grid view. I believe I am on the right track, but my environment is telling me otherwise.

Here is one of my data layer classes

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;

namespace Week9Lab_Hull.DataLayer
{
    
    public class BusinessObjects
    {


        #region ObjectDataSource Methods
        private String GetConnectionString()
        {
            return ConfigurationManager.ConnectionStrings["FanClubAccounts"].ConnectionString;
        }

        #endregion
        public List<FanClubAccounts> GetListOfAccounts()
        {
            // internal data object, instantiated
            List<FanClubAccounts> _categories = new List<FanClubAccounts>();
            using(SqlConnection obj = new SqlConnection(GetConnectionString()))
                        #region
            try
            {
                obj.Open();
                    //Step 1: Write sql command
                    SqlCommand cmd = new SqlCommand("SELECT * FROM FanClubAccounts", obj);
                    //step 2: populate data reader
                SqlDataReader reader = cmd.ExecuteReader(System.Data.Commandbehavior.CloseConnection);
                    //step 3: loop reader and populate list<>
                while (reader.Read())
                {
                 _categories.Add(new FanClubAccounts
                 {
                 CategoryID = (int)reader["AccountID"],
                 CategoryName =  reader["FirstName"].ToString(),
                // CategoryName =  reader["LastName"].ToString(),
                // CategoryName =  reader["Email"].ToString(),
                // CategoryName =  reader["Age"].ToString(),
//CategoryName =  reader["Gender"].ToString(),
                // CategoryName =  reader["FavoriteMovies"].ToString(),
                 //CategoryName =  reader["State"].ToString(),
                 //CategoryName =  reader["DateCreated"].ToString()
                 
                 });
                   
                }
 _categories.Insert(0, new FanClubAccounts { CategoryID = -1, CategoryName = "--Select--"});
            }
            catch (Exception ex) { string error = ex.Message; }
            finally { }
#endregion
            return _categories;
            }

        }


    
protected InsertMember()

string firstName
string lastname

// validation goes here

//update

BusinessObjects bo = new BusinessObjects();

bool isOkay = bo.InsertMember(varibles)


public Boolean InsertMember(@FirstName, pFirstname)
{ 
    myCommand.Para.Add(newSqlParameter(@variable, pFirstName));
MyConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();

return true
}



}//end class



Here is the other
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Week9Lab_Hull.DataLayer
{
    class DataModel
    {
   
    }


    public class FanClubAccounts
    {

            public int CategoryID { get; set; }
        public string CategoryName { get; set; } 
    
    }
}



And, here is my form code for the submission

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Windows.Forms;

namespace Week9Lab_Hull
{
    public partial class _Default : System.Web.UI.Page
    {


        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {


                if (tbFirstName.Text == "")
                    MessageBox.Show("A first name is required");
                        tbFirstName.Focus();
                   
                if (tbLastName.Text == "")
                MessageBox.Show("A last name is required");
                        tbLastName.Focus();
               
                if (tbEmail.Text == "")
                    MessageBox.Show("An email is required");
                        tbEmail.Focus();
                    
                    



            }


            catch (Exception ex )
            {

                Console.WriteLine("{0} Exception caught.", ex);
            
            }
                



        }
    }
}



I haven't reached the point of getting the submit button to take the data and input. I am trying to get my back end information straight first before I worry about making the user environment work.

Any help is appreciated

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Expected class, delegate, enum, interface, or struct

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3101
  • View blog
  • Posts: 10,377
  • Joined: 12-December 12

Re: Expected class, delegate, enum, interface, or struct

Posted 01 April 2013 - 05:09 PM

What is your environment telling you?! Post any error messages and indicate which lines in the posted-code they refer to.
Was This Post Helpful? 0
  • +
  • -

#3 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,054
  • Joined: 02-July 08

Re: Expected class, delegate, enum, interface, or struct

Posted 01 April 2013 - 05:17 PM

Am I reading this correct - you are initializing the BusinessObjects inside of itself? That is not right, you make this object in the page where you intend on using it - then it can be accessed by the controls and show the data.
Was This Post Helpful? 0
  • +
  • -

#4 khull1989  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 19-May 09

Re: Expected class, delegate, enum, interface, or struct

Posted 02 April 2013 - 06:35 AM

I may/may not be initializing the business objects in itself. Now that i look at it. I will have to check when i get home from work.
Was This Post Helpful? 0
  • +
  • -

#5 khull1989  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 19-May 09

Re: Expected class, delegate, enum, interface, or struct

Posted 02 April 2013 - 05:49 PM

The error that i am receiving is

Expected class, delegate, enum, interface, or struct \Week9Lab_Hull\Week9Lab_Hull\DataLayer\BusinessObjects.cs

it refers to lines 65, 74, and 79 in my business class layer

View Postandrewsw, on 01 April 2013 - 06:09 PM, said:

What is your environment telling you?! Post any error messages and indicate which lines in the posted-code they refer to.



The error that i am receiving is

Expected class, delegate, enum, interface, or struct \Week9Lab_Hull\Week9Lab_Hull\DataLayer\BusinessObjects.cs

it refers to lines 65, 74, and 79 in my business class layer

specifically under the Boolean, BusinessObjects, and InsertMember
Was This Post Helpful? 0
  • +
  • -

#6 rgfirefly24  Icon User is online

  • D.I.C Lover
  • member icon


Reputation: 262
  • View blog
  • Posts: 1,446
  • Joined: 07-April 08

Re: Expected class, delegate, enum, interface, or struct

Posted 03 April 2013 - 08:56 AM

What is this line protected InsertMember() it has no brackets, no semi-colon. It is confusing the compiler.

I would advise that you count your curly braces because it appears you are mismatched with them

This post has been edited by rgfirefly24: 03 April 2013 - 08:58 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1