Solved

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

Posted on 2011-09-09
6
249 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 19

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 74

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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 19

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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now