Solved

ObjectDataSource Wizard doesn't detect Class files in App_Code

Posted on 2008-10-08
6
295 Views
Last Modified: 2012-05-05
Hi,

I'm trying to set up a web site with Class files in the App_Code directory.  When using the ObjectDataWizard configuration set up wizard, the first screen reads "Select your business object"

The dropdown only contains references to my master page files, no sign of the .cs files I have created
0
Comment
Question by:krapvag
  • 3
  • 3
6 Comments
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 22670053
Hi,

Have You specified the component model attributes in your class files? I.e:

[System.ComponentModel.DataObject]

public partial class MyDataAccess {
    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public static DataSet GetMyData()    {

    }
}

/Carl.
0
 
LVL 1

Author Comment

by:krapvag
ID: 22670109
Thanks for the quick response.

I don't think I have.  Would I do this in the CS file?  I'm new to .net, so I've added the class file I'm trying to use

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Collections.Generic;

using System.Data.SqlClient;
 

/// <summary>

/// Summary description for TimePlanData

/// </summary>

/// 
 

public class TimePlanData

{
 

    private string _conString;
 

	public TimePlanData()

	{

        _conString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

	}
 

    public IList<TimePlan> GetTimePlans(int idFilter)

    {

        string sql = "SELECT * FROM TimePlan ";
 

        if (idFilter > 0)

        {

            sql += "where tp_id=" + idFilter;

        }
 

        sql += " order by tp_name";

        SqlConnection connection = null;

        IDataReader reader = null;
 

        IList<TimePlan> result = new List<TimePlan>();

        try

        {

            connection = new SqlConnection(_conString);

            connection.Open();

            IDbCommand cmd = connection.CreateCommand();

            cmd.CommandText = sql;

            reader = cmd.ExecuteReader();

            while (reader.Read())

            {

                result.Add(new TimePlan(reader));

            }

        }

        catch (Exception ex)

        {

        }

        finally

        {

            if (reader != null)

                reader.Close();

            if (connection != null)

                connection.Close();

        }

        return result;

    }
 

}

Open in new window

0
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 500 total points
ID: 22671506
Hi,

You should get by through changing your class file as the attached snippet.

/Carl.
using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Collections.Generic;

using System.Data.SqlClient;

using System.ComponentModel;
 

/// <summary>

/// Summary description for TimePlanData

/// </summary>

/// 

 

[DataObject(true)]

public class TimePlanData

{

 

    private string _conString;

 

	public TimePlanData()

	{

        _conString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

	}

    [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]

    public IList<TimePlan> GetTimePlans(int idFilter)

    {

        string sql = "SELECT * FROM TimePlan ";

 

        if (idFilter > 0)

        {

            sql += "where tp_id=" + idFilter;

        }

 

        sql += " order by tp_name";

        SqlConnection connection = null;

        IDataReader reader = null;

 

        IList<TimePlan> result = new List<TimePlan>();

        try

        {

            connection = new SqlConnection(_conString);

            connection.Open();

            IDbCommand cmd = connection.CreateCommand();

            cmd.CommandText = sql;

            reader = cmd.ExecuteReader();

            while (reader.Read())

            {

                result.Add(new TimePlan(reader));

            }

        }

        catch (Exception ex)

        {

        }

        finally

        {

            if (reader != null)

                reader.Close();

            if (connection != null)

                connection.Close();

        }

        return result;

    }

 

} 

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Author Closing Comment

by:krapvag
ID: 31504266
Excellent, thanks!

I take it for every other method I add, for example an Insert method, I put the line:
 [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]

before it?
0
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 22671895
Hi,

Yes, exactly.

/Carl.
0
 
LVL 1

Author Comment

by:krapvag
ID: 22842548
Hi,

I'm trying to add an Insert routine to this class file, but the ObjectDataSource wizard is only detecting the "GetData" method

It is not showing the "AddData" method, and when I type in "[DataObjectMethodAttribute" this is not detected in the intelisense


[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]

    public void AddData()

    {
 

    }
 

    [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]

    public IList<Data999> GetData(string telNumber)

    {

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now