SheetChangeEventHandler Problem

  • Thread starter Win32, VB, .NET n COM Developer
  • Start date
W

Win32, VB, .NET n COM Developer

Hi everyone!

Im running into a problem using SheetChangeEventHandler.

We need to develop an application that binds to that event. When a cell
value changes we need to get that value and see if it is on a given row and
column and if matches a list of rows and columns we take that value and
insert it in a sql server 2005 table.

The problem we are facing now is that after changing some cells and
inserting the values on sql, the application stops to receive the
SheetChangeEventHandler event. I dont know why, the code seems right but it
keeps happening and the application doesnt catch any exception that might be
thrown. For example, you change one cell and the event fires resulting in the
value inserted in the sql server table. Then you change a few more with the
same results. Then you change another cell and nothing happens, the event
doesnt get fired and as a result the data is not inserted in the sql server
table.

The application is very simple. Is just a Windows Form that shows what is
doing the app, we connect to Excel at Form_Load where we set the delegate for
the event and the event implementation where we get the value and insert it
on the database.

Form_Load
objApp =
(Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
objApp.ActiveWorkbook.SheetChange += new
Microsoft.Office.Interop.Excel.WorkbookEvents_SheetChangeEventHandler(ActiveWorkbook_SheetChange);

Event Implementation
void ActiveWorkbook_SheetChange(object Sh,
Microsoft.Office.Interop.Excel.Range Target)
{
try
{
if (!IsNumeric(Target.Value2))
{
MessageBox.Show("Cell value is not numeric", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
string columna_excel = "R" + Target.Row + "C" + Target.Column;
lblmensajes.Text = "Updating data..." + columna_excel;
int result = data.SaveValue(columna_excel,
Convert.ToDecimal(Target.Value2), fecha);
if (result == 0)
{
data.UpdateControlTable(id_proveedor, "ult_actualizacion",
"GetDate()");
lblmensajes.Text = "Data was updated sucessfully.";
}
else
{
data.UpdateControlTable(id_proveedor, "error_int",
result.ToString());
lblmensajes.Text = "Error! Data was not updated.";
}
}
catch (Exception ex)
{
this.messsageForm.AddMessage(ex.ToString());
MessageBox.Show(ex.ToString());
}
}

I hope that anyone can help me.
Thanks in advance!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top