Dovberman
asked on
Column 'Colname' does not belong to table RowData.
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.CommandTyp e = System.Data.CommandType.Te xt;
cmdUpdatesDone1.ExecuteNon Query();
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(pstrSymbolNameS QL, pconStockSelect);
// Try to open database and read information.
SqlDataAdapter adpSymbol = new SqlDataAdapter();
adpSymbol.SelectCommand = new SqlCommand(pstrSymbolNameS QL, 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].ToS tring();
// DateTime dteQuoteDate = Convert.ToDateTime(rowQuot eHistory[" 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.GetDat aColumn(St ring columnName)
at System.Data.DataRow.get_It em(String columnName)
at StockProMax.Admin.Maintain DataWeekly .GetColVal ue(SqlConn ection pconStockSelect, String pstrSymbolNameSQL, String pstrColName, String pstrDataType) in c:\Users\David\Documents\V isual Studio 2012\Projects\StockPickerM ax\StockPi ckerMax\Ad min\Mainta inDataWeek ly.aspx.cs :line 1142
at StockProMax.Admin.Maintain DataWeekly .Page_Load (Object sender, EventArgs e) in c:\Users\David\Documents\V isual Studio 2012\Projects\StockPickerM ax\StockPi ckerMax\Ad min\Mainta inDataWeek ly.aspx.cs :line 140
at System.Web.Util.CalliEvent HandlerDel egateProxy .Callback( Object sender, EventArgs e)
at System.Web.UI.Control.OnLo ad(EventAr gs e)
at System.Web.UI.Control.Load Recursive( )
at System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt)
InnerException:
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.CommandTyp
cmdUpdatesDone1.ExecuteNon
cmdUpdatesDone1.Dispose();
string strWorkCount;
strWorkCount = GetColValue(conStockSelect
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(pstrSymbolNameS
// Try to open database and read information.
SqlDataAdapter adpSymbol = new SqlDataAdapter();
adpSymbol.SelectCommand = new SqlCommand(pstrSymbolNameS
DataSet dstSymbol = new DataSet();
adpSymbol.Fill(dstSymbol, "RowData");
if (dstSymbol.Tables[0].Rows.
{
return "None";
}
else
{
DataRow rowSymbol = dstSymbol.Tables[0].Rows[0
string strColValue = rowSymbol[pstrColName].ToS
// DateTime dteQuoteDate = Convert.ToDateTime(rowQuot
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.GetDat
at System.Data.DataRow.get_It
at StockProMax.Admin.Maintain
at StockProMax.Admin.Maintain
at System.Web.Util.CalliEvent
at System.Web.UI.Control.OnLo
at System.Web.UI.Control.Load
at System.Web.UI.Page.Process
InnerException:
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
ASKER
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