Kpt.Khaos
Kpt.Khaos

Reputation: 693

Visual Studio not accessing instance of a class asp.net

I use this function List<LineData> list = LineData.getData(); in my aspx.cs page, to reference my class to get my data. Only problem is my query no longer contains the element I am receiving the error on. I receive a invalid object name error. I tried breakpoint and it never reaches any breakpoint I set even on page load (I put the breakpoint on the List<LineData> list = LineData.getData();) This is also very first thing on page load. We changed the database and I changed the connection string in the config file and the table name in my query. I do not understand why this is happening. I am not sure what code to post in the instance so what ever you want to see let me know.

**It says my old connectionstring is what is an invalid object name.

Stack Trace:

[SqlException (0x80131904): Invalid object name 'BeforeWorkOrder'.] DataClassLibrary.LineData.getData() +980 Line1.Page_Load(Object sender, EventArgs e) in c:\Users\K\Dropbox\K's Stuff\CoolerManagement\Line1.aspx.cs:16 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51 System.Web.UI.Control.OnLoad(EventArgs e) +92 System.Web.UI.Control.LoadRecursive() +54 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Here is the problem spot on my aspx.cs page

List<LineData> list = LineData.getData();

Here is my DataClass

public static List<LineData> getData()
{
    List<LineData> list = new List<LineData>();

    StringBuilder sqlString = new StringBuilder();
    sqlString.Append("SELECT * ");
    sqlString.Append("FROM WorkOrder ");
    sqlString.Append("WHERE LineCompleted =  'false' ");

    SqlDataReader reader = null;
    SqlConnection dbConn = DBHelper.getConnection();

    try
    {
        reader = DBHelper.executeQuery(dbConn, sqlString.ToString(), null);
        if (reader != null)
        {
            while (reader.Read())
            {
                **Data ld = new **Data();
                ld.OrderID = (int)reader["OrderID"];
                ld.PNumber = reader["PNumber"].ToString();
                ld.ItemCode = reader["CaseNum6"].ToString();
                ld.BrandCode = reader["CaseNum9"].ToString();
                ld.CasesRemaining = (int)reader["CasesRemaining"];
                ld.Group = (Group)reader["Group"];
                list.Add(ld);
            }
            reader.Close();
            reader.Dispose();
            dbConn.Close();
            dbConn.Dispose();
        }
        else
            throw new Exception("No records returned");
    }
    catch (Exception ex)
    {
        throw ex;
    }
    finally
    {
        if (dbConn != null)
        {
            try { dbConn.Close(); dbConn.Dispose(); }
            catch { }
        }
        if (reader != null)
        {
            try { reader.Close(); reader.Dispose(); }
            catch { }
        }
    }
    return list;
}

Upvotes: 4

Views: 181

Answers (1)

TTat
TTat

Reputation: 1496

It's probably a mismatch in your database table and your data model.

How to: Update an .edmx File when the Database Changes (Entity Data Model Tools): http://msdn.microsoft.com/en-us/library/vstudio/cc716697(v=vs.100).aspx

Upvotes: 1

Related Questions