Example #1
0
        /*Muestra los registros de la tabla en un gridview*/
        public void DisplayUserList(DataGridView grid)
        {
            myDataTable  = new DataTable();
            myCommand    = new SqlCommand("SP_ListUsers", MyConnection.GetConnection());
            mySqlAdapter = new SqlDataAdapter(myCommand);

            mySqlAdapter.Fill(myDataTable);
            if (myCommand.Connection.State == ConnectionState.Open)
            {
                myCommand.Connection.Close();
            }

            for (int i = 0; i < myDataTable.Rows.Count; i++)
            {
                myDataTable.Rows[i]["Nombre"]   = UpperFirstLetter(myDataTable.Rows[i]["Nombre"].ToString());
                myDataTable.Rows[i]["Apellido"] = UpperFirstLetter(myDataTable.Rows[i]["Apellido"].ToString());
            }

            grid.DataSource = myDataTable;
        }
Example #2
0
        /*Eliminar usuario*/
        public void DeleteUser(int id)
        {
            try
            {
                myCommand             = new SqlCommand("SP_DeleteUser", MyConnection.GetConnection());
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.Parameters.Add("@id", SqlDbType.Int).Value = id;

                myCommand.ExecuteNonQuery();

                if (myCommand.Connection.State == ConnectionState.Open)
                {
                    myCommand.Connection.Close();
                }
                MessageBox.Show("El usuario ha sido eliminado satisfactoriamente", "Eliminado", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }