Isidro Padilla

Isidro Padilla

  • 1.4k
  • 319
  • 19.5k

Why doesn’t this method work?

Apr 19 2020 11:59 AM
I am continuing with my SMO learning and again I am blocked.
 
Something is missing in this method that I am not able to see.
 
The view I have previously created it without problems, but when I try creating the delete method sends me the following message:
 
Reference or object Not instantiated to an object.
 
I hope a charitable soul lends me a hand.
  1. private void BtnBorrarVista_Click(object sender, EventArgs e)  
  2. {  
  3.       try  
  4.      {  
  5.                if (MessageBox.Show("Está intentando borrar la Vista " + textBoxBorrarVista.Text + " ¿Está seguro de que quiere eliminarla?",                "¡Atención!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)  
  6.                {     
  7.                         m_Server = new Server(cmbServerName.Text);  
  8.                         Database myNewDatabase = m_Server.Databases[cmbDbName.Text];  
  9.                         Microsoft.SqlServer.Management.Smo.View view = myNewDatabase.Views[textBoxBorrarVista.Text];  
  10.                         view.Drop();  
  11.                         MessageBox.Show("La Vista " + textBoxBorrarVista.Text + " se borró con éxito");  
  12.                }  
  13.                else  
  14.                {  
  15.                         MessageBox.Show("Operación abortada. La Vista " + textBoxBorrarVista.Text + " no se ha borrado");     
  16.                }  
  17.       }  
  18.       catch (Exception ex)  
  19.       {  
  20.             MessageBox.Show(ex.Message.ToString());  
  21.       }  
  22. }  

Answers (10)