private void Form1_Load(object sender, EventArgs e) { ClsDb db = new ClsDb(); try { dataGridView1.DataSource = db.consultarTabla("SELECT * FROM x"); } catch (Exception ex) { ClsHelper.erroLog(ex); } }
private void btnCrearCopia_Click(object sender, EventArgs e) { ClsDb ClsDb = new ClsDb(); String consulta; String dbName; SqlConnectionStringBuilder cn; try { this.Cursor = Cursors.WaitCursor; if (String.IsNullOrEmpty(txtRuta.Text)) { ClsHelper.MensajeSistema("Debe seleccionar la ruta donde guardarĂ¡ la copia"); return; } //if(!File.Exists(txtRuta.Text)) //{ // File.Create(txtRuta.Text); // if (!File.Exists(txtRuta.Text)) // { // ClsHelper.MensajeSistema("La ruta especificada no existe, por favor seleccione otra"); // } //} cn = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["cnDefault"].ConnectionString); dbName = cn.InitialCatalog; consulta = "BACKUP DATABASE " + dbName + " TO DISK = N'" + txtRuta.Text + "\\" + dbName + DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Hour.ToString() + "." + DateTime.Now.Minute.ToString() + "." + DateTime.Now.Second.ToString() + ".bak' WITH NOFORMAT, NOINIT, NAME =N'" + dbName + "-Full Database Backup',SKIP, STATS = 10"; cn.InitialCatalog = "Master"; ClsDb.ejecutarConsulta(consulta, new SqlConnection(cn.ConnectionString)); ClsHelper.MensajeSistema("Copia realizada correctamente"); } catch (Exception ex) { ClsHelper.erroLog(ex); } finally { this.Cursor = Cursors.Default; } }