Solved

How can I know if my database code is working or no ?

Posted on 2011-09-09
6
256 Views
Last Modified: 2012-05-12
Hi Expert,

That code was working perfect on my old website. I've move it to my tst network. I have an error and I'm not sure if my Database string is correct or what is wrong.

Server Error in '/' Application.

Compilation Error


Source Error:

 

Line 14:                   <TD bgColor="#eeeeee" colSpan="2">
Line 15:                         <P>
Line 16:                               <asp:checkboxlist id="CheckboxCategories" runat="server" repeatColumns="4" oninit="CheckboxCategories_Init" CellPadding="2" CellSpacing="2" CssClass="main" EnableViewState="False"></asp:checkboxlist></P>
Line 17:                   </TD>
Line 18:             </TR>
 
0
Comment
Question by:LelloLello
  • 3
  • 2
6 Comments
 

Author Comment

by:LelloLello
ID: 36511584

Attached file for your review... Why i'm getting that error oninit="CheckboxCategories_Init" ??

Server Error in '/' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: 'ASP.layouts_sublayouts_db_contentsearchablelistofworks_ascx' does not contain a definition for 'CheckboxCategories_Init' and no extension method 'CheckboxCategories_Init' accepting a first argument of type 'ASP.layouts_sublayouts_db_contentsearchablelistofworks_ascx' could be found (are you missing a using directive or an assembly reference?)

Source Error:

 

Line 14:                   <TD bgColor="#eeeeee" colSpan="2">
Line 15:                         <P>
Line 16:                               <asp:checkboxlist id="CheckboxCategories" runat="server" repeatColumns="4" oninit="CheckboxCategories_Init" CellPadding="2" CellSpacing="2" CssClass="main" EnableViewState="False"></asp:checkboxlist></P>
Line 17:                   </TD>
Line 18:             </TR>
 



 ContentSearchableListOfWorks-asc.cs ContentSearchableListOfWorks.ascx
0
 
LVL 20

Accepted Solution

by:
Daniel Van Der Werken earned 400 total points
ID: 36511735
Add this in your OnInit():

        protected override void OnInit( EventArgs e )
        {
            CheckBoxCategories.Init += new EventHandler( CheckBoxCategories_Init ); //<== this
            base.OnInit( e );
        }

Also, I don't think you really need the oninit="CheckboxCategories_Init" in your ASCX file.

Also, you might want to change this:
AutoEventWireup="true"

to this:
AutoEventWireup="false"
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 100 total points
ID: 36511756
Your markup page lists the page as inheriting a class under one namespace, but your code-behind is listed in a different namespace. Is this intentional?

ContentSearchableListOfWorks.ascx
Inherits="DB.layouts.sublayouts.DB.ContentSearchableListOfWorks"

ContentSearchableListOfWorks-asc.cs
namespace CCFA.layouts.sublayouts.dB
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:LelloLello
ID: 36511899
Kaufmed, it's correct on my original file i've just change the name here. but it is the same.
0
 

Author Comment

by:LelloLello
ID: 36511978
Dan7el, here is the orginal code.  Please copy to your visual studio and advice where i should add this ONIT ?


Dan7el, here is the original code.

======================================
ContentSearchableListOfWorks.ascx.cs 
=======================================

using System;

namespace CCFA.layouts.sublayouts.ArtBank
{
  using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
	using System.Data.SqlClient;
   /// using Microsoft.ContentManagement.Publishing;
    using System.Text.RegularExpressions;

    public partial class ContentSearchableListOfWorks : System.Web.UI.UserControl
    {
        
		protected System.Data.SqlClient.SqlConnection MyConnection;
		protected System.Data.SqlClient.SqlCommand oCmd;
		protected System.Web.UI.WebControls.Literal artWorksSearch;
		protected System.Web.UI.WebControls.ImageButton ImageButton;
		protected System.Web.UI.WebControls.TextBox TextBox;
		protected System.Web.UI.WebControls.Label searchInstructions;
		protected System.Web.UI.WebControls.CheckBoxList CheckboxCategories;
		protected System.Web.UI.WebControls.DataGrid SearchResults;
		protected System.Data.SqlClient.SqlDataReader oDR;

        protected void Page_Load(object sender, EventArgs e)
        {
<%-- start --%> 
    artWorksSearch.Text = "";
			// check the language
			Posting CurrentPosting = (Posting)CmsHttpContext.Current.ChannelItem;
			CustomPropertyCollection myCustomProperties = (CustomPropertyCollection)CurrentPosting.CustomProperties;
				
			
			if (myCustomProperties["cpLanguage"].Value == "eng") 
			{
				// english Category
				searchInstructions.Text  = "Artist Name:";
				ImageButton.ImageUrl = "http://www.artbank.ca/artbank/images/misc/button_go_grey-e.gif";
				ImageButton.AlternateText = "go";
			} 
			else 
			{
				// french Categorie
				searchInstructions.Text  = "Nom de l'artiste:";
				//ImageButton.ImageUrl = "../images/misc/button_go_grey-f.gif";
                ImageButton.ImageUrl = "http://www.artbank.ca/artbank/images/misc/button_go_grey-f.gif";
				ImageButton.AlternateText = "recherche";
			}
<%-- end --%> 
        }
        <%--- Start 2 --->
        public void searchSubmit_Click(object Source, System.Web.UI.ImageClickEventArgs E)
		{
			Posting myPosting = (Posting)CmsHttpContext.Current.Posting;
			CustomPropertyCollection myCustomProperties = (CustomPropertyCollection)myPosting.CustomProperties;

			//** M-A you will have to change this

            string myConnectionString = "server=SCCAPP1;database=CCAA;User ID=abc;password=123";
			//create  a comma delimited string of values
			string myCheckboxes ="";
			int i=0;
			foreach (ListItem myListItem in CheckboxCategories.Items)
			{
				if (myListItem.Selected == true && myCheckboxes.Length > 0 && i < CheckboxCategories.Items.Count) 
				{
					myCheckboxes += "," + myListItem.Value;
				} 
				else if (myListItem.Selected == true) 
				{
					myCheckboxes += myListItem.Value;
				}
				i++;
			}

			if (myCheckboxes == "") 
			{
				myCheckboxes = "999";
			}

			string myCommandString = "SELECT Artist_Name,Title,Execution_Date,E_Category,F_Category,ABBA_List_No FROM Art_Summary (NOLOCK) WHERE Category_Code IN (" + myCheckboxes + ") AND Artist_Name LIKE '" + Regex.Replace(TextBox.Text, "'", "' + CHAR(39) + '") + "%' ORDER BY Artist_Name, Execution_Date";
			
			SqlDataAdapter dataAdaptor = new SqlDataAdapter(myCommandString,myConnectionString);
			DataSet dataSet = new DataSet();

			dataAdaptor.Fill(dataSet);
			DataTable dataTable = dataSet.Tables[0];
				
			SearchResults.DataSource=dataTable;
			
			//artist column
			BoundColumn myColumn = new BoundColumn();
			myColumn.DataField = "Artist_Name";
			if (myCustomProperties["cpLanguage"].Value == "eng") 
			{// english
				myColumn.HeaderText = "Artist";
				if (myCheckboxes == "999" )
				{
					myColumn.FooterText = "Please select at least one category.";
				}
				else
				{
					myColumn.FooterText = "No records returned";
				}

			} 
			else 
			{ // french
				myColumn.HeaderText = "L'artiste";
				if (myCheckboxes == "999" )
				{
					myColumn.FooterText = "Veuillez choisir au moins une catégorie.";
				}
				else
				{
					myColumn.FooterText = "Aucun enregistrement trouvé";
				}
				
			}
			myColumn.ItemStyle.Width = 200;
			myColumn.ItemStyle.VerticalAlign = VerticalAlign.Top;
			SearchResults.Columns.Add(myColumn);

			//Title column
			myColumn = new BoundColumn();
			myColumn.DataField = "Title";
			if (myCustomProperties["cpLanguage"].Value == "eng") 
			{// english
				myColumn.HeaderText = "Title";
			} 
			else 
			{ // french
				myColumn.HeaderText = "Titre";
			}
			myColumn.ItemStyle.Width = 200;
			myColumn.ItemStyle.VerticalAlign = VerticalAlign.Top;
			SearchResults.Columns.Add(myColumn);

			//Date column
			myColumn = new BoundColumn();
			myColumn.DataField = "Execution_Date";
			if (myCustomProperties["cpLanguage"].Value == "eng") 
			{// english
				myColumn.HeaderText = "Date";
			} 
			else 
			{ // french
				myColumn.HeaderText = "Date";
			}
			myColumn.ItemStyle.Width = 50;
			myColumn.ItemStyle.VerticalAlign = VerticalAlign.Top;
			SearchResults.Columns.Add(myColumn);

			// category column
			myColumn = new BoundColumn();
			myColumn.DataField = "E_Category";
			if (myCustomProperties["cpLanguage"].Value == "eng") 
			{// english
				myColumn.HeaderText = "Category";
			} 
			else 
			{ // french
				myColumn.HeaderText = "Catégorie";
			}
			myColumn.ItemStyle.Width = 75;
			myColumn.ItemStyle.VerticalAlign = VerticalAlign.Top;
			SearchResults.Columns.Add(myColumn);

			// id column
			myColumn = new BoundColumn();
			myColumn.DataField = "ABBA_List_No";
			myColumn.ItemStyle.Wrap = false;
			myColumn.ItemStyle.Width = 75;
			myColumn.ItemStyle.VerticalAlign = VerticalAlign.Top;
			if (myCustomProperties["cpLanguage"].Value == "eng") 
			{// english
				myColumn.HeaderText = "ID";
			} 
			else 
			{ // french
				myColumn.HeaderText = "ID";
			}
			SearchResults.Columns.Add(myColumn);
			
			SearchResults.DataBind();
			if (SearchResults.Items.Count == 0)
				SearchResults.ShowFooter = true;
			else
				SearchResults.ShowFooter = false;
			
		}


		public void CheckboxCategories_Init(object Source, EventArgs E)
		{
			//** M-A you will have to change this
			MyConnection = new SqlConnection("server=SCCAPP1;database=CCAA;User ID=abc;password=123");

           	oCmd = new SqlCommand();
			oCmd.Connection = MyConnection;
			oCmd.Connection.Open();
			oCmd.CommandText = "SELECT DISTINCT Category_Code, E_Category, F_Category from Art_Summary (NOLOCK)";
			oDR = oCmd.ExecuteReader();

			Posting myPosting = (Posting)CmsHttpContext.Current.Posting;
			CustomPropertyCollection myCustomProperties = (CustomPropertyCollection)myPosting.CustomProperties;

			while (oDR.Read())
			if (myCustomProperties["cpLanguage"].Value == "eng") 
				{
					// english 
					ListItem myListItem = new ListItem();
					myListItem.Selected = false;
					myListItem.Text = oDR["E_Category"].ToString();
					myListItem.Value = oDR["Category_Code"].ToString();	
					CheckboxCategories.Items.Add(myListItem);
					} 
				else 
				{
					//french
				ListItem myListItem = new ListItem();
				myListItem.Selected = false;
				myListItem.Text = oDR["F_Category"].ToString();
				myListItem.Value = oDR["Category_Code"].ToString();	
				CheckboxCategories.Items.Add(myListItem);
			} 	

			oDR.Close();
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.SearchResults.SelectedIndexChanged += new System.EventHandler(this.SearchResults_SelectedIndexChanged);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void SearchResults_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		
		}
        <%--- End 2 --->
    }
}


==========================================
==========================================
ContentSearchableListOfWorks.ascx
==========================================
==========================================
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ContentSearchableListOfWorks.ascx.cs" Inherits="CCFA.layouts.sublayouts.ArtBank.ContentSearchableListOfWorks" %> 
<%@ Import Namespace="Sitecore.Data.Items" %>
<%@ Import Namespace="Sitecore.Links" %>


<sc:FieldRenderer ID="frBody" runat="server" FieldName="Body" />

<P>
	<asp:Literal id="artWorksSearch" runat="server"></asp:Literal></P>
									
<P>
	<TABLE id="Table1" cellSpacing="2" cellPadding="0" width="100%" border="0">
		<TR>
			<TD bgColor="#eeeeee" colSpan="2">
				<P>
					<asp:checkboxlist id="CheckboxCategories" runat="server" repeatColumns="4" oninit="CheckboxCategories_Init" CellPadding="2" CellSpacing="2" CssClass="main" EnableViewState="False"></asp:checkboxlist></P>
			</TD>
		</TR>
		<TR>
			<TD colSpan="2">
				<P><BR>
					<asp:Label id="searchInstructions" for="TextBox" runat="server">Label</asp:Label></P>
			</TD>
		</TR>
		<TR>
			<TD width="10%">
				<asp:textbox id="TextBox" runat="server" CssClass="main"></asp:textbox></TD>
			<TD vAlign="center" width="90%">
				<asp:imagebutton id="ImageButton" onclick="searchSubmit_Click" runat="server" ImageUrl="../images/misc/button_go_grey-e.gif"></asp:imagebutton></TD>
		</TR>
		<TR>
			<TD colSpan="2"><BR>
				<asp:DataGrid id="SearchResults" runat="server" AutoGenerateColumns="False" Width="100%" CellPadding="2" BorderWidth="0px" GridLines="None" PageSize="20">
					<AlternatingItemStyle BackColor="#EEEEEE"></AlternatingItemStyle>
					<ItemStyle CssClass="main"></ItemStyle>
					<HeaderStyle Font-Bold="True" CssClass="main" BackColor="Silver"></HeaderStyle>
					<FooterStyle Font-Size="Smaller" ForeColor="Red"></FooterStyle>
				</asp:DataGrid>
			</TD>
		</TR>
	</TABLE>
</P>




<p>&nbsp;</p>

Open in new window

0
 
LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 36525186

#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
		        this.CheckboxCategories.Init += new EventHandler( CheckboxCategories_Init ); //<== Add this
			this.SearchResults.SelectedIndexChanged += new System.EventHandler(this.SearchResults_SelectedIndexChanged);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

Open in new window

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

803 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