Solved

Column 'Colname' does not belong to table RowData.

Posted on 2014-02-19
3
1,241 Views
Last Modified: 2014-02-20
I cannot figure this out.

The same code with other sql statements works in other pages.

Here is the code.

strSQL returns 7933 from the SQL Server Management window.

 strSQL = "SELECT Count(*) FROM SymbolWork1 AS WorkCount";  Cast as string
            SqlCommand cmdUpdatesDone1 = new SqlCommand(strSQL, conStockSelect);
            cmdUpdatesDone1.CommandType = System.Data.CommandType.Text;
            cmdUpdatesDone1.ExecuteNonQuery();
            cmdUpdatesDone1.Dispose();

            string strWorkCount;
            strWorkCount = GetColValue(conStockSelect, strSQL, "WorkCount", "String");
            lblStatus.Text = "Weekly update done " + strWorkCount + " SymbolWork1 rows created." ;
            conStockSelect.Close();

      private string GetColValue(SqlConnection pconStockSelect, string pstrSymbolNameSQL, string pstrColName, string pstrDataType)
        // Gets column value based on the SQL Select string
 
        {
            SqlCommand cmd = new SqlCommand(pstrSymbolNameSQL, pconStockSelect);

            // Try to open database and read information.

            SqlDataAdapter adpSymbol = new SqlDataAdapter();
            adpSymbol.SelectCommand = new SqlCommand(pstrSymbolNameSQL, pconStockSelect);

            DataSet dstSymbol = new DataSet();
            adpSymbol.Fill(dstSymbol, "RowData");

            if (dstSymbol.Tables[0].Rows.Count == 0)
            {
                return "None";
            }
            else
            {
                DataRow rowSymbol = dstSymbol.Tables[0].Rows[0];

                string strColValue = rowSymbol[pstrColName].ToString();
                // DateTime dteQuoteDate = Convert.ToDateTime(rowQuoteHistory["QuoteDate"]);

                return strColValue;
            }
        }

System.ArgumentException was unhandled by user code
  HResult=-2147024809
  Message=Column 'WorkCount' does not belong to table RowData.
  Source=System.Data
  StackTrace:
       at System.Data.DataRow.GetDataColumn(String columnName)
       at System.Data.DataRow.get_Item(String columnName)
       at StockProMax.Admin.MaintainDataWeekly.GetColValue(SqlConnection pconStockSelect, String pstrSymbolNameSQL, String pstrColName, String pstrDataType) in c:\Users\David\Documents\Visual Studio 2012\Projects\StockPickerMax\StockPickerMax\Admin\MaintainDataWeekly.aspx.cs:line 1142
       at StockProMax.Admin.MaintainDataWeekly.Page_Load(Object sender, EventArgs e) in c:\Users\David\Documents\Visual Studio 2012\Projects\StockPickerMax\StockPickerMax\Admin\MaintainDataWeekly.aspx.cs:line 140
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:
0
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 500 total points
ID: 39872053
here you go

I think you have to change the below

strSQL = "SELECT Count(*) FROM SymbolWork1 AS WorkCount";  Cast as string

to

strSQL = "SELECT Count(*) AS WorkCount FROM SymbolWork1 ";  

although the previous is a valid sql statement it is aliasing the table name instead of the column name, so you effectively you renamed symbolwork1 rather than workcount.
0
 

Author Comment

by:Dovberman
ID: 39873034
That explains why it works in 20 other places.

Does not work
strSQL = "SELECT Count(*) FROM SymbolWork1 AS WorkCount";

Works
string strMaxPctChgSQL = "SELECT MAX(PctChg) As MaxPctChg FROM Exceptions";

string strMaxPctChg = GetColValue(conStockSelect,

Thank you
0
 

Author Closing Comment

by:Dovberman
ID: 39873035
Thank you.
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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