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
VulpesPosted Mar 23, 2012, 1:57 PM
Chevy Mark SunderlandPosted Mar 24, 2012, 1:06 PM
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
VulpesPosted Mar 24, 2012, 9:15 AM
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 SunderlandPosted Mar 23, 2012, 2:13 PM
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:
Chevy Mark SunderlandPosted Mar 23, 2012, 1:41 PM
I tried your code, but I have new error:
VulpesPosted Mar 23, 2012, 12:17 PM
Chevy Mark SunderlandPosted Mar 22, 2012, 5:55 PM
There is an already open DataReader associated with this command
VulpesPosted Mar 22, 2012, 12:10 PM
So, I'd insert the line I've highlighted below:
Chevy Mark SunderlandPosted Mar 22, 2012, 11:22 AM
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();
VulpesPosted Mar 22, 2012, 10:23 AM
Are you sure that your LIKE clause is working OK?
Chevy Mark SunderlandPosted Mar 22, 2012, 8:32 AM
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();
VulpesPosted Mar 22, 2012, 8:24 AM
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.