Hello there, thanks for your time.
First of all I must say that I am a newbie when it comes to ASP NET.
Here is my problem in attachment file.
Your help would be very appreciated.
Compiler Error Message: CS0103: The name 'VarPerc' does not exist in the current context
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

VulpesRank #55 · 29.2K reputationPosted Mar 23, 2012, 9:57 AM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 22, 2012, 4:24 AM EDT
objCmd.Parameters.Add("?VarPerc", OdbcType.VarChar, 15).Value = VarPerc;
I can't tell from the code you've uploaded where VarPerc is defined but, for you to get that particular error message, it's not currently within scope.
If you've defined it in a different method then you could store it in Session state and then retrieve it in the current method.
Chevy Mark Sunderland159 reputationPosted Mar 22, 2012, 4:32 AM EDT
I have changed method, but I have this other error, why?
Exception Details: System.IndexOutOfRangeException: VarPerc
String myQuery = " SELECT " +
" CONCAT( VarPerc,'%') As VarPerc " +
" FROM tbl_m " +
" WHERE " +
" tNome LIKE '%PPP%'; ";
OdbcConnection myConnectionString =
new OdbcConnection(
ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
myConnectionString.Open();
OdbcCommand objCmd = new OdbcCommand(myQuery, myConnectionString);
objCmd.Prepare();
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = myQuery;
OdbcDataReader reader = objCmd.ExecuteReader();
while (reader.Read())
Response.Write(reader["VarPerc"].ToString());
reader.Close();
Chart1.DataSource = objCmd.ExecuteReader();
VulpesRank #55 · 29.2K reputationPosted Mar 22, 2012, 6:23 AM EDT
Are you sure that your LIKE clause is working OK?
Chevy Mark Sunderland159 reputationPosted Mar 22, 2012, 7:22 AM EDT
I try debug:
1) The myQuery in mysql working correctly;
2) I have add new field in the myQuery (tName);
3) I have canceled the syntax CONCAT(VarPerc,'%') As VarPerc in the myQuery;
3) I rem the last line of bind to Chart1;
4) I try with Response.Write(reader[1].ToString());
5) I have add the last line of bind to Chart1;
The output of alias `VarPerc` is correct = -59
Now I need use the value of alias `VarPerc` in codebehind and try this but I have error.
Can you help me?
Exception Details: System.InvalidOperationException:
There is already an open DataReader associated with this Command which must be closed first.
Source Error:
Line 599: Chart1.DataSource = objCmd.ExecuteReader();
String myQuery = " SELECT tNome, " +
" VarPerc As VarPerc " +
" FROM tbl_m " +
" WHERE " +
" tNome LIKE '%PPP%'; ";
OdbcConnection myConnectionString =
new OdbcConnection(
ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
myConnectionString.Open();
OdbcCommand objCmd = new OdbcCommand(myQuery, myConnectionString);
objCmd.Prepare();
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = myQuery;
OdbcDataReader reader = objCmd.ExecuteReader();
while (reader.Read())
Response.Write(reader["VarPerc"].ToString());
String top = reader["VarPerc"].ToString();
LegendItem newItem = new LegendItem();
newItem.ImageStyle = LegendImageStyle.Marker;
newItem.MarkerStyle = MarkerStyle.Diamond;
newItem.Cells.Add(LegendCellType.SeriesSymbol, "", ContentAlignment.MiddleLeft);
newItem.Cells.Add(LegendCellType.Text, "top", ContentAlignment.MiddleLeft);
newItem.Cells[1].CellSpan = 2;
newItem.Cells.Add(LegendCellType.Text, "", ContentAlignment.MiddleLeft);
newItem.Cells.Add(LegendCellType.Text, top, ContentAlignment.MiddleLeft);
Chart1.Legends[0].CustomItems.Add(newItem);
Chart1.DataSource = objCmd.ExecuteReader();
objCmd.Dispose();
objCmd.Cancel();
reader.Dispose();
reader.Close();
myConnectionString.Dispose();
myConnectionString.Close();
VulpesRank #55 · 29.2K reputationPosted Mar 22, 2012, 8:10 AM EDT
So, I'd insert the line I've highlighted below:
Chevy Mark Sunderland159 reputationPosted Mar 22, 2012, 1:55 PM EDT
There is an already open DataReader associated with this command
VulpesRank #55 · 29.2K reputationPosted Mar 23, 2012, 8:17 AM EDT
Chevy Mark Sunderland159 reputationPosted Mar 23, 2012, 9:41 AM EDT
I tried your code, but I have new error:
Chevy Mark Sunderland159 reputationPosted Mar 23, 2012, 10:13 AM EDT
With your last suggestion, I don't have error in the page asp net.
But I don't print the value of the `String top = reader["VarPerc"].ToString();`
I attachment new output image:
1) upper left side (top to left) I have the correct output of `reader["VarPerc"].ToString();` "-59";
2) lower right side (bottom to right) I don't have the same value.
The new code:
VulpesRank #55 · 29.2K reputationPosted Mar 24, 2012, 5:15 AM EDT
However, I notice that 'top' appears in this line:
newItem.Cells.Add(LegendCellType.Text, top, ContentAlignment.MiddleLeft);
Is that in fact the line which controls what's displayed at the lower right hand corner of the chart?
If it is and nothing is being displayed, then it would suggest that 'top' is either null or an empty string.
Chevy Mark Sunderland159 reputationPosted Mar 24, 2012, 9:06 AM EDT
The problem now is solved your code works properly with the latest changes, but I have problem with the remote hosting dbms MySql not updated by hosting webmaster. I'm sorry.
Thanks a lot !!!
Cheers