C# compile problem with custom web control
-
Hi everyone. My situation is long but not very complicated. It involves custom web controls. Any help is very much appreciated. I am building a custom web control. I am creating this control because I have a scenario where I need to dynamically output different types of content to a page (sometimes an image, sometimes a table, sometimes a string of text). As such, a label, or image or control wouldn't do. So, I created a custom web control. This control has a property for a URL string. The URL is inputted to the control and then it inputs the url to a SQL stored procedure. The stored procedure returns a value with the type of output to return (text, table, etc), and it renders the output based on the value. My problem is at compile time. When I compile my code, I get a bunch of errors which make no sense at all! I'm not sure where it's coming from. Here the code from where I begin getting compile errors: protected override void Render(HtmlTextWriter output) { if (Format.Type == "Unknown") { MyNameSpace.MyClass myClass = new MyNameSpace.MyClass(); SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); SqlCommand myCommand = new SqlCommand("GetOutput", myConnection); // Mark the Command as a SPROC myCommand.CommandType = CommandType.StoredProcedure; // Add Parameters to SPROC SqlParameter parameterPage = new SqlParameter("@URL", SqlDbType.NVarChar, 100); parameterPage.Value = Format.Page; myCommand.Parameters.Add(parameterPage); SqlParameter parameterType = new SqlParameter("@Type", SqlDbType.NVarChar, 30); parameterType.Value = ParameterDirection.Output; myCommand.Parameters.Add(parameterType); myConnection.Open(); SqlDataReader pageoutput = myCommand.ExecuteReader(CommandBehavior.CloseConnection); // check if it is a table if ((String) pageoutput["TableCell"] != null) { SqlDataReader dr = myClass.GetTableContents(Format.Page); bool hasMoreRows = dr.Read(); if (hasMoreRows != null) { // start writing the table output.Write("table header cell here"); // it is on this next line that is 133, where the compile errors start occuring while (hasMoreRows == true) { // this if statement checks if the reader is an even or odd item depth, and //if it is even it renders a different background color the table (creating // an alternating patten effect) if ((dr.Depth % 2) == 0) { output.Write("alternating style table HTML here"); } else { output.Write("normal table style here"); } } } } } } } } These are
-
Hi everyone. My situation is long but not very complicated. It involves custom web controls. Any help is very much appreciated. I am building a custom web control. I am creating this control because I have a scenario where I need to dynamically output different types of content to a page (sometimes an image, sometimes a table, sometimes a string of text). As such, a label, or image or control wouldn't do. So, I created a custom web control. This control has a property for a URL string. The URL is inputted to the control and then it inputs the url to a SQL stored procedure. The stored procedure returns a value with the type of output to return (text, table, etc), and it renders the output based on the value. My problem is at compile time. When I compile my code, I get a bunch of errors which make no sense at all! I'm not sure where it's coming from. Here the code from where I begin getting compile errors: protected override void Render(HtmlTextWriter output) { if (Format.Type == "Unknown") { MyNameSpace.MyClass myClass = new MyNameSpace.MyClass(); SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); SqlCommand myCommand = new SqlCommand("GetOutput", myConnection); // Mark the Command as a SPROC myCommand.CommandType = CommandType.StoredProcedure; // Add Parameters to SPROC SqlParameter parameterPage = new SqlParameter("@URL", SqlDbType.NVarChar, 100); parameterPage.Value = Format.Page; myCommand.Parameters.Add(parameterPage); SqlParameter parameterType = new SqlParameter("@Type", SqlDbType.NVarChar, 30); parameterType.Value = ParameterDirection.Output; myCommand.Parameters.Add(parameterType); myConnection.Open(); SqlDataReader pageoutput = myCommand.ExecuteReader(CommandBehavior.CloseConnection); // check if it is a table if ((String) pageoutput["TableCell"] != null) { SqlDataReader dr = myClass.GetTableContents(Format.Page); bool hasMoreRows = dr.Read(); if (hasMoreRows != null) { // start writing the table output.Write("table header cell here"); // it is on this next line that is 133, where the compile errors start occuring while (hasMoreRows == true) { // this if statement checks if the reader is an even or odd item depth, and //if it is even it renders a different background color the table (creating // an alternating patten effect) if ((dr.Depth % 2) == 0) { output.Write("alternating style table HTML here"); } else { output.Write("normal table style here"); } } } } } } } } These are
bool is a value type, not a reference type so you can't compare it to null. The datareader returns true if there are more rows to read, and false if there are none. Other than that, I see no errors on my end. I'm using RC0 on XP Pro James