Exemplo n.º 1
0
        public bool Reader(string nombre, List <SqlParameter> parametros)
        {
            bool answ;

            try
            {
                Abrir();
                SqlCommand    comando = CrearComando(nombre, parametros);
                SqlDataReader reader  = comando.ExecuteReader();
                if (reader.HasRows)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (SqlException ex)
            {
                SqlError err     = ex.Errors[0];
                string   mensaje = string.Empty;
                mensaje = err.ToString();
                answ    = false;
            }
            Cerrar();
            return(answ);
        }
Exemplo n.º 2
0
        public static Boolean ManipulaErrorSQL(SqlException ex, string texto)
        {
            SqlError err     = ex.Errors[0];
            string   mensaje = string.Empty;
            Boolean  fill    = false;

            switch (err.Number)
            {
            case 547:
                mensaje = "No se pudo Eliminar o Insertar el Registro. Integridad de Datos.";
                fill    = true;
                break;

            case 2601:
                mensaje = "No se pudo Crear o Modificar el Registro. Valor Duplicado."; break;

            case 515:
                mensaje = "No se pudieron Salvar los Cambios al Registro Actual. Campos Obligatorios Vacios."; break;

            default:
                mensaje = Convert.ToString(err.Number) + "   " + err.ToString(); break;
            }
            MessageBox.Show(mensaje, texto, MessageBoxButtons.OK, MessageBoxIcon.Stop);
            return(fill);
        }
Exemplo n.º 3
0
 public void EjecutarConsulta2(ref string men)
 {
     try
     {
         this.comando.ExecuteReader();
         //this.comando.ExecuteNonQuery();
         men = "";
     }
     //catch (Exception)
     catch (SqlException ex)
     {
         SqlError err     = ex.Errors[0];
         string   mensaje = string.Empty;
         mensaje = err.ToString();
         men     = mensaje;
     }
 }
Exemplo n.º 4
0
        public DbDataReader EjecutarConsulta3(ref string men)
        {
            try
            {
                men = "";
                return(this.comando.ExecuteReader());
            }
            //catch (Exception)
            catch (SqlException ex)
            {
                SqlError err     = ex.Errors[0];
                string   mensaje = string.Empty;
                mensaje = err.ToString();
                men     = mensaje;

                return(null);
            }
        }
Exemplo n.º 5
0
        //SE SALVA LA INFORMACION MODIFICADA /////
        // //////////////////////////////////////////////////////////
        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                decimal Cantidad;
                decimal Salario;
                decimal SalarioVenta;
                try { Cantidad = Convert.ToDecimal(cantidadTextBox.Text); }
                catch { Cantidad = 0; }
                try { Salario = Convert.ToDecimal(salNormalTextBox.Text); }
                catch { Salario = 0; }
                try { SalarioVenta = Convert.ToDecimal(textBox2.Text); }
                catch { SalarioVenta = 0; }

                int  nIdObra      = Convert.ToInt32(promowork_dataDataSet.Tables["HorasTrabajadasDias"].Rows[horasTrabajadasDiasDataGridView.CurrentCell.RowIndex]["IdObra"]);
                int  nITrabajador = Convert.ToInt32(comboBox1.SelectedValue);
                byte nMesEmpresa  = Convert.ToByte(promowork_dataDataSet.Tables["HorasTrabajadasDias"].Rows[0]["MesEmpresa"]);
                int  nAnoEmpresa  = Convert.ToInt32(promowork_dataDataSet.Tables["HorasTrabajadasDias"].Rows[0]["AnoEmpresa"]);

                queriesTableAdapter1.CambiaActualizaHorasTrabajadas(nIdObra, nITrabajador, VariablesGlobales.nIdUsuarioActual, (horasTrabajadasDiasDataGridView.CurrentCell.ColumnIndex + 1), nMesEmpresa, nAnoEmpresa, Cantidad, Convert.ToInt32(idTipoComboBox.SelectedValue), Convert.ToBoolean(festivoCheckBox.CheckState), Salario, SalarioVenta);
                horasTrabajadasDiasDataGridView.CurrentCell.Value = Cantidad;
                salarioTrabajadorActualTableAdapter.Fill(promowork_dataDataSet.SalarioTrabajadorActual, VariablesGlobales.nIdEmpresaActual, nMesEmpresa, nAnoEmpresa, Convert.ToInt32(comboBox1.SelectedValue));

                groupBox1.Visible = false;
            }
            catch (DBConcurrencyException)
            {
                MessageBox.Show("No se Pudo Salvar la Información. El Registro fue modificado por otro Usuario.", "Error");
            }
            catch (SqlException ex)
            {
                SqlError err     = ex.Errors[0];
                string   mensaje = string.Empty;
                switch (err.Number)
                {
                case 547:
                    mensaje = "Es Obligatirio Definir un tipo de Pago Válido."; break;

                default:
                    mensaje = Convert.ToString(err.Number) + "   " + err.ToString(); break;
                }
                MessageBox.Show(mensaje, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
Exemplo n.º 6
0
        public int Scalar(string nombre, List <SqlParameter> parametros)
        {
            var scl = 0;

            Abrir();
            SqlCommand comando = CrearComando(nombre, parametros);

            try
            {
                scl = Convert.ToInt32(comando.ExecuteScalar());
            }

            catch (SqlException ex)
            {
                SqlError err     = ex.Errors[0];
                string   mensaje = string.Empty;
                mensaje = err.ToString();
                scl     = -1;
            }
            Cerrar();
            return(scl);
        }
Exemplo n.º 7
0
        public int Escribir(string nombre, List <SqlParameter> parametros)
        {
            int filasAfectadas = 0;

            Abrir();
            SqlCommand comando = CrearComando(nombre, parametros);

            try
            {
                filasAfectadas = comando.ExecuteNonQuery();
            }

            catch (SqlException ex)
            {
                SqlError err     = ex.Errors[0];
                string   mensaje = string.Empty;
                mensaje        = err.ToString();
                filasAfectadas = -1;
            }
            Cerrar();
            return(filasAfectadas);
        }
Exemplo n.º 8
0
        public DataTable ObtenerTabla(String NombreTabla, String Sql)
        {
            DataSet        ds       = new DataSet();
            SqlConnection  Conexion = ObtenerConexion();
            SqlDataAdapter adp      = ObtenerAdaptador(Sql, Conexion);

            try
            {
                adp.Fill(ds, NombreTabla);
                Conexion.Close();
            }
            catch (SqlException ex)
            {
                SqlError err     = ex.Errors[0];
                string   mensaje = string.Empty;
                switch (err.Number)
                {
                case 109:
                    mensaje = "Problemas con insert"; break;

                case 110:
                    mensaje = "Más problemas con insert"; break;

                case 113:
                    mensaje = "Problemas con comentarios"; break;

                case 156:
                    mensaje = "Error de sintaxis"; break;

                default:
                    mensaje = err.ToString();
                    break;
                }
                System.Diagnostics.Debug.WriteLine("Error con BBDD: {0}", mensaje);
            }

            return(ds.Tables[NombreTabla]);
        }
Exemplo n.º 9
0
 /// <inheritdoc />
 public override string ToString()
 {
     return(SqlError.ToString());
 }
Exemplo n.º 10
0
 public void ShowSqlError(SqlError error)
 {
     Console.WriteLine(error.ToString());
 }
Exemplo n.º 11
0
 public CrateException(SqlError error)
     : base(error.ToString())
 {
 }
Exemplo n.º 12
0
        public void TestSqlExceptionPrototype()
        {
            Parallel.For(
                0,
                100,
                i =>
            {
                Random random = Tester.RandomGenerator;
                SqlErrorCollectionPrototype errorCollectionPrototype =
                    new SqlErrorCollectionPrototype();

                int loops = Tester.RandomGenerator.Next(10) + 1;
                for (int loop = 0; loop < loops; loop++)
                {
                    // Generate random values.
                    int infoNumber       = random.RandomInt32();
                    byte errorState      = random.RandomByte();
                    byte errorClass      = (byte)random.Next(1, 26);
                    string server        = random.RandomString();
                    string errorMessage  = random.RandomString();
                    string procedure     = random.RandomString();
                    int lineNumber       = random.RandomInt32();
                    uint wind32ErrorCode = (uint)Math.Abs(random.RandomInt32());

                    // Create prototype.
                    SqlErrorPrototype sqlErrorPrototype = new SqlErrorPrototype(
                        infoNumber,
                        errorState,
                        errorClass,
                        server,
                        errorMessage,
                        procedure,
                        lineNumber,
                        wind32ErrorCode);

                    // Test implicit cast
                    SqlError sqlError = sqlErrorPrototype;
                    Assert.IsNotNull(sqlError);

                    // Check SqlError created properly
                    Assert.AreEqual(infoNumber, sqlError.Number);
                    Assert.AreEqual(errorState, sqlError.State);
                    Assert.AreEqual(errorClass, sqlError.Class);
                    Assert.AreEqual(server, sqlError.Server);
                    Assert.AreEqual(errorMessage, sqlError.Message);
                    Assert.AreEqual(procedure, sqlError.Procedure);
                    Assert.AreEqual(lineNumber, sqlError.LineNumber);
                    Assert.AreEqual(sqlErrorPrototype.ToString(), sqlError.ToString());

                    errorCollectionPrototype.Add(sqlError);
                }

                Assert.AreEqual(loops, errorCollectionPrototype.Count);

                // Test implicit cast
                SqlErrorCollection collection = errorCollectionPrototype;

                Assert.AreSame(errorCollectionPrototype.SqlErrorCollection, collection);

                // Now create a SqlException
                Guid connectionId = Guid.NewGuid();
                SqlExceptionPrototype sqlExceptionPrototype = new SqlExceptionPrototype(
                    collection,
                    "9.0.0.0",
                    connectionId);

                // Test implicit conversion
                SqlException sqlException = sqlExceptionPrototype;
                Assert.IsNotNull(sqlException);

                // Check SqlException created properly - it uses the first error from the collection.
                SqlError first = collection[0];
                Debug.Assert(first != null);
                Assert.AreEqual(first.Number, sqlException.Number);
                Assert.AreEqual(first.State, sqlException.State);
                Assert.AreEqual(first.Class, sqlException.Class);
                Assert.AreEqual(first.Server, sqlException.Server);
                //Assert.AreEqual(first.Message, sqlException.Message);
                Assert.AreEqual(first.Procedure, sqlException.Procedure);
                Assert.AreEqual(first.LineNumber, sqlException.LineNumber);
            });
        }
Exemplo n.º 13
0
        private DataTable SQL_Query(string query)
        {
            var connection = checkBox1.Checked ? new SqlConnection("Data Source=DESKTOP-BH2UN3B\\SQLEXPRESS;Integrated Security=True") : new SqlConnection("Data Source=192.168.0.16;Initial Catalog=BirrUp;User ID=sa;Password=BirrUp-root;");

            try
            {
                // Table to store the query results
                DataTable table = new DataTable();

                if (check_connection())
                {
                    // Creates a SQL connection
                    using (connection)
                    {
                        connection.Open();

                        // Creates a SQL command
                        using (var command = new SqlCommand(query, connection))
                        {
                            // Loads the query results into the table
                            table.Load(command.ExecuteReader());
                        }

                        connection.Close();

                        label1.Text      = "Query done";
                        label1.ForeColor = Color.LawnGreen;

                        return(table);
                    }
                }
                else
                {
                    label1.Text      = "Sin server";
                    label1.ForeColor = Color.Coral;
                }
            }
            catch (SqlException ex)
            {
                SqlError err     = ex.Errors[0];
                string   mensaje = string.Empty;
                switch (err.Number)
                {
                case 109:
                    mensaje = "Problemas con insert"; break;

                case 110:
                    mensaje = "Más problemas con insert"; break;

                case 113:
                    mensaje = "Problemas con comentarios"; break;

                case 156:
                    mensaje = "Error de sintaxis"; break;

                default:
                    mensaje = err.ToString(); break;
                }
                label1.Text      = "Error con BBDD: {0}" + mensaje;
                label1.ForeColor = Color.Coral;
            }
            catch (Exception ex)
            {
                label1.Text      = "Error de otra cosa: {0}" + ex.Message;
                label1.ForeColor = Color.Coral;
            }
            finally
            {
                connection.Close();
            }
            return(null);
        }