?
Solved

.NET event

Posted on 2011-09-02
5
Medium Priority
?
214 Views
Last Modified: 2012-05-12
Trying to save to database on event. Not saving, error message (Not saved) displays. Don't know how to debug in .net.

Code behind page attached.
using System;
using System.Threading;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls; 
using System.Xml;
using ComponentArt.Web.UI;
using System.Data.OleDb;



public class WebForm1 : System.Web.UI.Page
{
  protected ComponentArt.Web.UI.Editor Editor1;
  protected System.Data.OleDb.OleDbConnection dbCon; 
  private void Page_Load(object sender, System.EventArgs e)
  {
  
    // Hook the Save event to the Editor
    Editor1.Save += new Editor.SaveEventHandler(Editor1_Save);

    // Initialization
    if(!Page.IsPostBack)
    {
      Editor1.ClientEvents.SaveSuccess = new ClientEvent("Editor_saveSuccess");
      Editor1.ClientEvents.SaveError = new ClientEvent("Editor_saveError");
    }

    // Load saved content to session, if we have it
    if(Session["Editor_Data"] != null)
    {
      Editor1.ContentHTML = (string)Session["Editor_Data"];
    }
  }

  private void Editor1_Save(object sender, EditorSaveEventArgs args)
  {
    // Save content to session
	  string sql; 

    Session["Editor_Data"] = args.Content;


	
	string conStr = "Provider=SQLOLEDB.1;Password=xxxxxxxxxxxxxx;Persist Security Info=True;User ID=xxxxxxxxxx;Initial Catalog=xxxxxxxxxx;Data Source=xxxxxxxxxxxxxxxx";
    dbCon = new System.Data.OleDb.OleDbConnection(conStr); 
    dbCon.Open(); 
	
	sql = "update ecommPageCopy set ";
              //sql += "[PageCopy] = '" + Editor1.ContentHTML + "' ";
              sql += "[PageCopy] = 'TEST CONTENT'" ;
				
				//sql += " where ProductId = " + id; 
				sql += " where ProductId = 326"; 
	System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(sql, dbCon); 
		      cmd.ExecuteNonQuery();




  }





  #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);
  }
  
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {    
    this.Load += new System.EventHandler(this.Page_Load);
  }
  #endregion
}

Open in new window

0
Comment
Question by:webdork
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:gopaltayde
ID: 36475073
Add try..catch block around below code, in catch you will able to see the exception and detail message, why it is not saving. eg

try
{
string conStr = "Provider=SQLOLEDB.1;Password=xxxxxxxxxxxxxx;Persist Security Info=True;User ID=xxxxxxxxxx;Initial Catalog=xxxxxxxxxx;Data Source=xxxxxxxxxxxxxxxx";
    dbCon = new System.Data.OleDb.OleDbConnection(conStr);
    dbCon.Open();
      
      sql = "update ecommPageCopy set ";
              //sql += "[PageCopy] = '" + Editor1.ContentHTML + "' ";
              sql += "[PageCopy] = 'TEST CONTENT'" ;
                        
                        //sql += " where ProductId = " + id;
                        sql += " where ProductId = 326";
      System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(sql, dbCon);
                  cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
}
0
 

Author Comment

by:webdork
ID: 36475205
is the word "try" part of the code?
0
 
LVL 14

Accepted Solution

by:
binaryevo earned 2000 total points
ID: 36475735
yes:

try
{
    Do stuff here
}
catch(Exception ex)
{
    Handle errors here
}
0
 

Author Comment

by:webdork
ID: 36475882
error
Compiler Error Message: CS1519: Invalid token 'catch' in class, struct, or interface member declaration
0
 
LVL 14

Expert Comment

by:binaryevo
ID: 36489305
Can you upload the project ( if its not to big )?
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 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